Speed up update_local_storage in sync #1024
Closed
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.
Description
Stop importing source GPG keys during sync. We have a place on
Source
to store fingerprint and key, which is all we need for the import, and which is what we check when deciding whether to enable the reply box, so let's just update the database here and defer import to the keyring until someone actually wants to reply. It takes milliseconds that won't be noticed then, but do add up during sync.Avoid dirtying synced objects on update unless they've actually changed.
Use maps instead of sets to hold local objects in the
update_
functions, so it's faster to check if we already have a record of incoming objects.Reduce the number of database queries during sync: cache sources or journalists instead of looking them up for each incoming object associated with them.
Note that this stops short of switching to SQLAlchemy's bulk operations, so we may be able to speed
update_local_storage
up more when we can take the time to do that.Fixes #1009.
Test Plan
NUM_SOURCES=1000
(reduce key size to 1024 insecuredrop/crypto_util.py
line 123 to reduce startup time).LOGLEVEL=debug ./run.sh --sdc-home ~/.securedrop_client
update_local_storage
operations withgrep duration ~/.securedrop_client/logs/client.log
. None should take longer than about seven seconds with 1000 sources, and most should be quite a bit faster than that.Checklist
If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:
If these changes add or remove files other than client code, packaging logic (e.g., the AppArmor profile) may need to be updated. Please check as applicable: