mirror of https://github.com/mastodon/mastodon
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
* refactor(statuses_vacuum): remove dead code - unused Method is not called inside class and private. Clean up dead code. * refactor(statuses_vacuum): make retention_period present test explicit This private method only hides functionality. It is best practice to be as explicit as possible. * refactor(statuses_vacuum): improve query performance - fix statuses_scope having sub-select for Account.remote scope by `joins(:account).merge(Account.remote)` - fix statuses_scope unnecessary use of `Status.arel_table[:id].lt` because it is inexplicit, bad practice and even slower than normal `.where('statuses.id < ?'` - fix statuses_scope remove select(:id, :visibility) for having reusable active record query batches (no re queries) - fix vacuum_statuses! to use in_batches instead of find_in_batches, because in_batches delivers a full blown active record query result, in stead of an array - no requeries necessary - send(:unlink_from_conversations) not to perform another db query, but reuse the in_batches result instead. - remove now obsolete remove_from_account_conversations method - remove_from_search_index uses array of ids, instead of mapping the ids from an array - this should be more efficient - use the in_batches scope to call delete_all, instead of running another db query for this - because it is again more efficient - add TODO comment for calling models private method with send * refactor(status): simplify unlink_from_conversations - add `has_many through:` relation mentioned_accounts - use model scope local instead of method call `Status#local?` - more readable add account to inbox_owners when account.local? * refactor(status): searchable_by way less sub selects These queries all included a sub-select. Doing the same with a joins should be more efficient. Since this method does 5 such queries, this should be significant, since it technically halves the query count. This is how it was: ```ruby [3] pry(main)> Status.first.mentions.where(account: Account.local, silent: false).explain Status Load (1.6ms) SELECT "statuses".* FROM "statuses" WHERE "statuses"."deleted_at" IS NULL ORDER BY "statuses"."id" DESC LIMIT $1 [["LIMIT", 1]] Mention Load (1.5ms) SELECT "mentions".* FROM "mentions" WHERE "mentions"."status_id" = $1 AND "mentions"."account_id" IN (SELECT "accounts"."id" FROM "accounts" WHERE "accounts"."domain" IS NULL) AND "mentions"."silent" = $2 [["status_id", 109382923142288414], ["silent", false]] => EXPLAIN for: SELECT "mentions".* FROM "mentions" WHERE "mentions"."status_id" = $1 AND "mentions"."account_id" IN (SELECT "accounts"."id" FROM "accounts" WHERE "accounts"."domain" IS NULL) AND "mentions"."silent" = $2 [["status_id", 109382923142288414], ["silent", false]] QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=0.15..23.08 rows=1 width=41) -> Seq Scan on accounts (cost=0.00..10.90 rows=1 width=8) Filter: (domain IS NULL) -> Index Scan using index_mentions_on_account_id_and_status_id on mentions (cost=0.15..8.17 rows=1 width=41) Index Cond: ((account_id = accounts.id) AND (status_id = '109382923142288414'::bigint)) Filter: (NOT silent) (6 rows) ``` This is how it is with this change: ```ruby [4] pry(main)> Status.first.mentions.joins(:account).merge(Account.local).active.explain Status Load (1.7ms) SELECT "statuses".* FROM "statuses" WHERE "statuses"."deleted_at" IS NULL ORDER BY "statuses"."id" DESC LIMIT $1 [["LIMIT", 1]] Mention Load (0.7ms) SELECT "mentions".* FROM "mentions" INNER JOIN "accounts" ON "accounts"."id" = "mentions"."account_id" WHERE "mentions"."status_id" = $1 AND "accounts"."domain" IS NULL AND "mentions"."silent" = $2 [["status_id", 109382923142288414], ["silent", false]] => EXPLAIN for: SELECT "mentions".* FROM "mentions" INNER JOIN "accounts" ON "accounts"."id" = "mentions"."account_id" WHERE "mentions"."status_id" = $1 AND "accounts"."domain" IS NULL AND "mentions"."silent" = $2 [["status_id", 109382923142288414], ["silent", false]] QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=0.15..23.08 rows=1 width=41) -> Seq Scan on accounts (cost=0.00..10.90 rows=1 width=8) Filter: (domain IS NULL) -> Index Scan using index_mentions_on_account_id_and_status_id on mentions (cost=0.15..8.17 rows=1 width=41) Index Cond: ((account_id = accounts.id) AND (status_id = '109382923142288414'::bigint)) Filter: (NOT silent) (6 rows) ``` |
2 years ago | |
---|---|---|
.. | ||
activitypub | 2 years ago | |
admin | 2 years ago | |
connection_pool | 6 years ago | |
importer | 3 years ago | |
nodeinfo | 6 years ago | |
ostatus | 6 years ago | |
rss | 3 years ago | |
settings | 4 years ago | |
translation_service | 2 years ago | |
vacuum | 2 years ago | |
access_token_extension.rb | 3 years ago | |
account_reach_finder.rb | 4 years ago | |
activity_tracker.rb | 4 years ago | |
application_extension.rb | 3 years ago | |
ascii_folding.rb | 3 years ago | |
cache_buster.rb | 4 years ago | |
delivery_failure_tracker.rb | 3 years ago | |
emoji_formatter.rb | 2 years ago | |
entity_cache.rb | 4 years ago | |
extractor.rb | 3 years ago | |
fast_geometry_parser.rb | 4 years ago | |
fast_ip_map.rb | 5 years ago | |
feed_manager.rb | 2 years ago | |
hash_object.rb | 8 years ago | |
hashtag_normalizer.rb | 2 years ago | |
html_aware_formatter.rb | 3 years ago | |
inline_renderer.rb | 2 years ago | |
link_details_extractor.rb | 3 years ago | |
permalink_redirector.rb | 3 years ago | |
plain_text_formatter.rb | 3 years ago | |
potential_friendship_tracker.rb | 4 years ago | |
rate_limiter.rb | 5 years ago | |
redis_configuration.rb | 3 years ago | |
request.rb | 2 years ago | |
request_pool.rb | 6 years ago | |
response_with_limit.rb | 5 years ago | |
scope_parser.rb | 3 years ago | |
scope_transformer.rb | 3 years ago | |
search_query_parser.rb | 6 years ago | |
search_query_transformer.rb | 3 years ago | |
status_cache_hydrator.rb | 2 years ago | |
status_filter.rb | 7 years ago | |
status_finder.rb | 6 years ago | |
status_reach_finder.rb | 2 years ago | |
suspicious_sign_in_detector.rb | 3 years ago | |
tag_manager.rb | 3 years ago | |
text_formatter.rb | 3 years ago | |
themes.rb | 8 years ago | |
toc_generator.rb | 6 years ago | |
translation_service.rb | 2 years ago | |
user_settings_decorator.rb | 3 years ago | |
vacuum.rb | 3 years ago | |
validation_error_formatter.rb | 4 years ago | |
video_metadata_extractor.rb | 3 years ago | |
webfinger.rb | 3 years ago | |
webfinger_resource.rb | 5 years ago |