Moving some counter queries out of subqueries in the API
This commit is contained in:
parent
4b5b953d42
commit
fc90d38893
9 changed files with 62 additions and 9 deletions
|
@ -13,14 +13,19 @@ class Api::V1::StatusesController < ApiController
|
|||
|
||||
def context
|
||||
@context = OpenStruct.new(ancestors: @status.ancestors(current_account), descendants: @status.descendants(current_account))
|
||||
set_maps([@status] + @context[:ancestors] + @context[:descendants])
|
||||
statuses = [@status] + @context[:ancestors] + @context[:descendants]
|
||||
|
||||
set_maps(statuses)
|
||||
set_counters_maps(statuses)
|
||||
end
|
||||
|
||||
def reblogged_by
|
||||
results = @status.reblogs.paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
||||
accounts = Account.where(id: results.map(&:account_id)).with_counters.map { |a| [a.id, a] }.to_h
|
||||
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
||||
@accounts = results.map { |r| accounts[r.account_id] }
|
||||
|
||||
set_account_counters_maps(@accounts)
|
||||
|
||||
next_path = reblogged_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
||||
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
||||
|
||||
|
@ -31,9 +36,11 @@ class Api::V1::StatusesController < ApiController
|
|||
|
||||
def favourited_by
|
||||
results = @status.favourites.paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
|
||||
accounts = Account.where(id: results.map(&:account_id)).with_counters.map { |a| [a.id, a] }.to_h
|
||||
accounts = Account.where(id: results.map(&:account_id)).map { |a| [a.id, a] }.to_h
|
||||
@accounts = results.map { |f| accounts[f.account_id] }
|
||||
|
||||
set_account_counters_maps(@accounts)
|
||||
|
||||
next_path = favourited_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
||||
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue