This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
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.
Improve performance of
remove_hidden_devices_from_device_inbox
#11420Improve performance of
remove_hidden_devices_from_device_inbox
#11420Changes from 2 commits
3f26c10
6e3a0f8
ee96e39
e3a1a17
c7baa7a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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