Add counter caches for a large performance increase on API requests
This commit is contained in:
parent
333e44c3fc
commit
de22c202f5
13 changed files with 41 additions and 22 deletions
|
@ -20,7 +20,7 @@ class Api::V1::AccountsController < ApiController
|
|||
accounts = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h
|
||||
@accounts = results.map { |f| accounts[f.target_account_id] }
|
||||
|
||||
set_account_counters_maps(@accounts)
|
||||
# set_account_counters_maps(@accounts)
|
||||
|
||||
next_path = following_api_v1_account_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||
prev_path = following_api_v1_account_url(since_id: results.first.id) unless results.empty?
|
||||
|
@ -35,7 +35,7 @@ class Api::V1::AccountsController < ApiController
|
|||
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)
|
||||
# set_account_counters_maps(@accounts)
|
||||
|
||||
next_path = followers_api_v1_account_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||
prev_path = followers_api_v1_account_url(since_id: results.first.id) unless results.empty?
|
||||
|
@ -52,8 +52,8 @@ class Api::V1::AccountsController < ApiController
|
|||
@statuses = cache_collection(@statuses, Status)
|
||||
|
||||
set_maps(@statuses)
|
||||
set_counters_maps(@statuses)
|
||||
set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
||||
# set_counters_maps(@statuses)
|
||||
# set_account_counters_maps(@statuses.flat_map { |s| [s.account, s.reblog? ? s.reblog.account : nil] }.compact.uniq)
|
||||
|
||||
next_path = statuses_api_v1_account_url(max_id: @statuses.last.id) unless @statuses.empty?
|
||||
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
|
||||
|
@ -117,7 +117,7 @@ class Api::V1::AccountsController < ApiController
|
|||
def search
|
||||
@accounts = AccountSearchService.new.call(params[:q], limit_param(DEFAULT_ACCOUNTS_LIMIT), params[:resolve] == 'true', current_account)
|
||||
|
||||
set_account_counters_maps(@accounts) unless @accounts.nil?
|
||||
# set_account_counters_maps(@accounts) unless @accounts.nil?
|
||||
|
||||
render action: :index
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue