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