Improve performance of queries for unseen submissions #5872
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.
Status
Ready for review
Description of Changes
With large numbers of sources or submissions, the journalist interface index page queries could exceed the 60-second Apache timeout. This uses joins instead of the n+1 checks for submission seen status, both there and when downloading unread submissions.
Testing
In a SecureDrop 1.8.0 environment with Apache (staging, hardware, prod VMs), create a large number of sources and submissions. Running
loaddata.py --source-count 1000
is enough to demonstrate the performance change. If you want to run into the Apache timeout, increase the number of sources, or add more messages and files to each source.Then log in to the journalist interface and load the index page several times, watching the network timing in Tor Browser's developer tools. With 1000 sources, the page should probably take around 20-30 seconds to load.
To confirm the cause:
config.py
to addSQLALCHEMY_RECORD_QUERIES = True
to theFlaskConfig
.journalist_app/main.py
to make the end ofindex
look like this:Restarting Apache and reloading the index page should spam
/var/log/apache2/journalist-error.log
with a lot of this:Now, check out this branch and either build debs and install
securedrop-app-code
on the app server, or just copy the two files changed in this PR to/var/www/securedrop
and restart Apache. Again, reload the journalist index page several times. It should load in much less time, around 2-4 seconds in my testing. If you change the end ofindex
again,/var/log/apache2/journalist-error.log
should only contain a few queries for each load of the page.The same query strategy change was made to the download of unread items. Ensure that you have a few sources with unread items, and confirm that you can properly download unread items for a single source via the
{num} unread
button in its row, or multiple selected sources and theDownload Unread
button at the top of the page. Make sure to also try downloading unread items for a source or sources with no unread items.Deployment
No special considerations.
Checklist
If you made changes to the server application code:
make lint
) and tests (make test
) pass in the development containerIf you made non-trivial code changes:
Choose one of the following: