logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe
commit: a1c54220e8e79c4bb0cc20da193888388efe2ba4
parent: df7dbc41ae08647a02b2171fd1bfce143acec610
Author: unarist <m.unarist@gmail.com>
Date:   Fri, 13 Oct 2017 23:53:44 +0900

Optimize Status#permitted_for 500x (account timeline) (#5373)

The main change of this PR is removing `order by visibility` hack.

This was introduced to force using of `index_statuses_on_account_id` instead of PK index, but it seems no longer needed probably due to `index_statuses_on_account_id_id`. Removing this avoids reading all rows, so really improves first fetching of the user who has lot of statuses.

I have also changed JOIN to IN + subquery, which slightly faster in most cases.

Diffstat:

Mapp/models/status.rb4+---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/app/models/status.rb b/app/models/status.rb @@ -220,9 +220,7 @@ class Status < ApplicationRecord # non-followers can see everything that isn't private/direct, but can see stuff they are mentioned in. visibility.push(:private) if account.following?(target_account) - joins("LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = #{account.id}") - .where(arel_table[:visibility].in(visibility).or(Mention.arel_table[:id].not_eq(nil))) - .order(visibility: :desc) + where(visibility: visibility).or(where(id: account.mentions.select(:status_id))) end end