Conversation
| ADD COLUMN instance_id int REFERENCES instance (id) ON UPDATE CASCADE ON DELETE CASCADE, | ||
| ADD COLUMN community_id int REFERENCES community (id) ON UPDATE CASCADE ON DELETE CASCADE, | ||
| -- drop the check constraint | ||
| DROP CONSTRAINT notification_check; |
There was a problem hiding this comment.
This should be added back, similar to modlog_check with different values depending on kind
There was a problem hiding this comment.
Once I get the performance stuff done I'll re-add this.
There was a problem hiding this comment.
K done, and it works on prod lemmy.ml data.
| ALTER TABLE comment | ||
| ADD COLUMN community_id int REFERENCES community (id) ON UPDATE CASCADE ON DELETE CASCADE; | ||
|
|
||
| -- Fill the rows | ||
| UPDATE | ||
| comment AS c |
There was a problem hiding this comment.
I've been running this on my dev machine now for 3 days, and its still not done.
Really not sure what to do about it, because I do believe it'd massively speed up our comment queries.
And removing community from the CommentView (and just making CommentViewSlim the default) isn't really an option IMO unless we want to remove all community-type context from comments. Which means comments can't be viewed from /home (at least without showing the community context) or /community
EDIT: This could have been due to the trigger on comment filling search_combined, which is gone now in main. I'm rerunning.
|
Finally finished the long migration adding |
|
Comment listings for a post, report combined, and notifications are still slow after this. Its been a long day trying to figure these out.
|
| pub federation_pending: bool, | ||
| /// Whether the comment is locked. | ||
| pub locked: bool, | ||
| /// This field is a dupe of post.community_id, but necessary for join performance. |
There was a problem hiding this comment.
This is the API documentation, but the comment is completely irrelevant for API clients so better leave it out here. Or use a simple // comment. You can also consider making these fields as #[serde(skip)] so we can remove/change them in the future without any breaking API change.
|
Is this ready to merge? Not entirely clear from your last comment. You mentioned that the migration is very slow and bloats the table, how is the duration and table size now? The comment queries look quite slow compared to others. Could this simply be because they are returning more data (in bytes) compared to your other tests? This could explain why Multi-community queries are very fast compared to Communities, even though queries are very similar. I also wonder how long GetComments takes with 0.19 with the same setup, to see if 400ms is reasonable or not. Its very odd that some modlog queries take ~300ms, while most of them are around 30ms. |
I've spent many days on these, and exhausted my expertise on SQL. It really needs some other eyes besides mine, although at least the performance is passable for most things.
Comment table changes
community_idcolumn on thecommenttable, which allows for faster moderation_view, and subscription views (ie, we can usecomment::community_id.eq_any)ListingType::ModeratorView, andListingType::Suggestednot crash out. It also balloons the size of the comment table.CommentListingType, and remove those from it. Or even better, just removelisting_typefor comment entirely.Notification / report_combined
community_id,instance_idcolumns to notifications, and makes all the inserts to notifications insert the relevant fields also. These ended up not bringing big speed improvements, but did simplify the joins.report_combined, which again the improvements were not very large.report_combined, andnotifications, is just using themap_to_enumand building the large objects, while the SQL queries actually stayed below 100ms.CommentView, but just theComment. This would save a lot of joins, and still have the core comment info. It just wouldn't show things like your votes for that comment, whether the comment creator is banned, etc.Person saved / liked / content combined
post_idespecially when filling the comment, reduced a cascading joinORcondition.Full speed results. I'm mainly not happy with get comments for a post, list notifications, and list reports. But I don't think there's much more I can do there. I played around A LOT with joins, indexes, and filters, and was unable to do better than this.
List posts with different sorts
List posts for a community with different sorts
List posts with different listing types
List posts with show hidden
show hidden: 104ms
List posts with hide read
show read : 103ms
List posts with higher pages
List posts for a multi-community with different sorts
List communities with different sorts
List communities with different listing types
List multi-communities with different sorts
Get a community
get community: 23ms
Get a post
Get comments for a post with different sorts, tree
Get comments for a post with different sorts, flat
Get comments for a post slim
getCommentsSlim: 370ms
Get all comments with different sorts
Get comments with different types
List person content with types
List person saved with types
List person liked with types
List person read
list person read: 67ms
List person hidden
list person hidden: 26ms
List registration applications
List reports
List reports with type
Search with types
Notifications with types
Notifications with unread only
Liking a comment / post
Get modlog with types
Context : #5929