mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-09-11 20:57:44 +00:00
* 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) ``` |
||
---|---|---|
.. | ||
account | ||
account_suggestions | ||
admin | ||
concerns | ||
form | ||
trends | ||
web | ||
account.rb | ||
account_alias.rb | ||
account_conversation.rb | ||
account_deletion_request.rb | ||
account_domain_block.rb | ||
account_filter.rb | ||
account_migration.rb | ||
account_moderation_note.rb | ||
account_note.rb | ||
account_pin.rb | ||
account_stat.rb | ||
account_statuses_cleanup_policy.rb | ||
account_statuses_filter.rb | ||
account_suggestions.rb | ||
account_summary.rb | ||
account_warning.rb | ||
account_warning_preset.rb | ||
admin.rb | ||
announcement.rb | ||
announcement_filter.rb | ||
announcement_mute.rb | ||
announcement_reaction.rb | ||
appeal.rb | ||
application_record.rb | ||
backup.rb | ||
block.rb | ||
bookmark.rb | ||
canonical_email_block.rb | ||
content_retention_policy.rb | ||
context.rb | ||
conversation.rb | ||
conversation_mute.rb | ||
custom_emoji.rb | ||
custom_emoji_category.rb | ||
custom_emoji_filter.rb | ||
custom_filter.rb | ||
custom_filter_keyword.rb | ||
custom_filter_status.rb | ||
device.rb | ||
domain_allow.rb | ||
domain_block.rb | ||
email_domain_block.rb | ||
encrypted_message.rb | ||
export.rb | ||
extended_description.rb | ||
favourite.rb | ||
featured_tag.rb | ||
feed.rb | ||
follow.rb | ||
follow_recommendation.rb | ||
follow_recommendation_filter.rb | ||
follow_recommendation_suppression.rb | ||
follow_request.rb | ||
home_feed.rb | ||
identity.rb | ||
import.rb | ||
instance.rb | ||
instance_filter.rb | ||
invite.rb | ||
invite_filter.rb | ||
ip_block.rb | ||
list.rb | ||
list_account.rb | ||
list_feed.rb | ||
login_activity.rb | ||
marker.rb | ||
media_attachment.rb | ||
mention.rb | ||
message_franking.rb | ||
mute.rb | ||
notification.rb | ||
one_time_key.rb | ||
poll.rb | ||
poll_vote.rb | ||
preview_card.rb | ||
preview_card_provider.rb | ||
preview_card_trend.rb | ||
privacy_policy.rb | ||
public_feed.rb | ||
relationship_filter.rb | ||
relay.rb | ||
remote_follow.rb | ||
report.rb | ||
report_filter.rb | ||
report_note.rb | ||
rule.rb | ||
scheduled_status.rb | ||
search.rb | ||
session_activation.rb | ||
setting.rb | ||
site_upload.rb | ||
status.rb | ||
status_edit.rb | ||
status_pin.rb | ||
status_stat.rb | ||
status_trend.rb | ||
system_key.rb | ||
tag.rb | ||
tag_feed.rb | ||
tag_follow.rb | ||
tombstone.rb | ||
trends.rb | ||
unavailable_domain.rb | ||
user.rb | ||
user_invite_request.rb | ||
user_ip.rb | ||
user_role.rb | ||
web.rb | ||
webauthn_credential.rb | ||
webhook.rb |