This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve performance of remove_hidden_devices_from_device_inbox
#11420
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3f26c10
Improve performance of remove_hidden_devices_from_device_inbox
babolivier 6e3a0f8
Changelog
babolivier ee96e39
Fix column order
babolivier e3a1a17
Don't pick up progress from a half-finished run of the previous implem
babolivier c7baa7a
Merge changelog with #11421
babolivier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve performance of various background updates related to device inboxes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this limit will mean that we may not find all the
device_inbox
rows for a given user - we may only end up deleting half of them before deciding to move onto the next user.I think a better strategy is to remove the join against
device_inbox
, and just look for hidden devices, without worrying about whether they havedevice_inbox
rows. Then, do aDELETE FROM device_inbox
for each such device.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to do this initially, but the original docstring mentions that it might be a bit heavy if the device has tons of pending messages in its inbox. For example, on abolivier.bzh's database, I've got devices with over 60k rows in
device_inbox
(which aren't hidden devices but that's probably because I've already run the previous incarnation of this update), which sounds like a lot to delete in one go.On top of that, I don't see how we might not delete entries for all devices for a given user, given the condition in the query is
user_id >= ?
, so if we don't do every device from a user we should just do the rest in the next run?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sorry, you're right.
However, from your analysis in the PR comment:
this is no good. It's a scan of the entirety of the
device_inbox_user_stream_id
index: there is noindex cond
here. It's acceptable for your local db with 100k rows, but won't be for a larger db.Honestly, looking at this again, I think we're better off rewriting it again (sorry!) to do the same as #11421 (ie, walk through the
device_inbox
table for a sequence of stream_ids. Hell, why not combine it with #11421?other ideas...
stream_ids
for that device on each run of the bg update. That gets annoyingly fiddly in terms of tracking state, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think you're right here, let's combine it with #11421