Introduce indexes to db tables, greatly improving performance. #5424
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.
This is a bit of a facepalm moment:
Our database tables of
HistoryEntry
andPageImage
didn't have indexes set up! Adding indexes to tables (especially tables that will grow very large) is super important for performance when making queries or doing migrations.I tested migrating a
HistoryEntry
table with 10000 entries. With our current db structure, the migration takes about 12 seconds, which accounts for the ANRs that we have seen from a small number of users.With this new structure with indexing, the migration (with 10000 entries) takes 100 milliseconds.
Note that adding indexes will necessitate another db version bump (to 28), and I added two new migration paths, 27→28 and 26→28, simply because version 27 is already in the wild (in our Beta version). But really the 26→28 migration will be the one that occurs in production, and this is the one that is now optimized for efficiency.