Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[performance] Database optimizations #419

Merged
merged 9 commits into from
Mar 7, 2022
Merged

Conversation

tsmethurst
Copy link
Contributor

This PR includes a database migration to add indexes on commonly-selected fields in database entries.

In testing on https://goblin.technology, this saw some queries go from taking about 150ms to taking 0.5ms, a 300x improvement.

From Matrix chat:

the most expensive queries (in the order of 100+ms) tend to be counts of statuses and complicated joins

in order to serialize a notification in the manner that masto expects, GtS has to do a lot of counting from the database (count number of statuses posted by this account, count number of replies/likes/faves on this status, that kind of thing)

so it runs queries like the following

SELECT "status"."created_at" FROM "statuses" AS "status" WHERE (account_id = '01Q0ER4N4DYAPM3141BZQ7B985') ORDER BY "id" DESC LIMIT 1

^^ so that finds the time of the most recent status by account 01Q0ER4N4DYAPM3141BZQ7B985

but statuses so far aren't indexed on anything except their primary key

so i believe adding indexes for things like account_id, uri, etc, should speed the selects and counts up, albeit at the cost of slower insertion times (which isn't really an issue anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant