When marking newly-backed up sessions, only fetch ones that are not backed up #2922
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.
Fixes element-hq/element-web#26488
(No public API changes.)
Explanation
When we receive a response saying that a key backup is complete, we must mark the sessions whose keys are not backed up as such, so we don't back them up again.
In the current code. we call
store.get_inbound_group_sessions()
, then filter the results to find those sessions that are associated with this backup. This is very slow as there can be a very large number of sessions.This PR is to call
store.inbound_group_sessions_for_backup()
instead. This method only fetches sessions that are not already backed up, which seems, if I understand it correctly, to be the exact set of sessions that we might want to mark as backed up at this time.What limit to use?
The big question is what maximum limit to pass in (
get_inbound_group_sessions
has no limit, which is part of the cause of this problem). The point is that there may be new sessions that are not part of this backup, so we can't just useSelf::BACKUP_BATCH_SIZE
, which is the maximum number of sessions in this backup. I chose a large number that should mean that we usually get all the relevant sessions.If we ever don't mark sessions as backed up even though they are, I am not sure of the consequences - I think maybe we will back them up again in the next backup, which would hopefully not be a problem.
If we ever had so many new sessions that the limit meant we never found any sessions to mark as backed up, that would be a problem, because we would never stop trying to back up the same sessions over and over again. I added an error log so we can at least identify the problem if it happens.