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
|
||||
|
|
|
@ -11,7 +11,7 @@ class Api::V1::BlocksController < 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] }.compact
|
||||
|
||||
set_account_counters_maps(@accounts)
|
||||
# set_account_counters_maps(@accounts)
|
||||
|
||||
next_path = api_v1_blocks_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||
prev_path = api_v1_blocks_url(since_id: results.first.id) unless results.empty?
|
||||
|
|
|
@ -11,7 +11,7 @@ class Api::V1::FavouritesController < ApiController
|
|||
@statuses = cache_collection(Status.where(id: results.map(&:status_id)), Status)
|
||||
|
||||
set_maps(@statuses)
|
||||
set_counters_maps(@statuses)
|
||||
# set_counters_maps(@statuses)
|
||||
|
||||
next_path = api_v1_favourites_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||
prev_path = api_v1_favourites_url(since_id: results.first.id) unless results.empty?
|
||||
|
|
|
@ -9,7 +9,7 @@ class Api::V1::FollowRequestsController < 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 = api_v1_follow_requests_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
|
||||
prev_path = api_v1_follow_requests_url(since_id: results.first.id) unless results.empty?
|
||||
|
|
|
@ -11,7 +11,7 @@ class Api::V1::MutesController < 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 = api_v1_mutes_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||
prev_path = api_v1_mutes_url(since_id: results.first.id) unless results.empty?
|
||||
|
|
|
@ -14,8 +14,8 @@ class Api::V1::NotificationsController < ApiController
|
|||
statuses = @notifications.select { |n| !n.target_status.nil? }.map(&:target_status)
|
||||
|
||||
set_maps(statuses)
|
||||
set_counters_maps(statuses)
|
||||
set_account_counters_maps(@notifications.map(&:from_account))
|
||||
# set_counters_maps(statuses)
|
||||
# set_account_counters_maps(@notifications.map(&:from_account))
|
||||
|
||||
next_path = api_v1_notifications_url(max_id: @notifications.last.id) unless @notifications.empty?
|
||||
prev_path = api_v1_notifications_url(since_id: @notifications.first.id) unless @notifications.empty?
|
||||
|
|
|
@ -23,7 +23,7 @@ class Api::V1::StatusesController < ApiController
|
|||
statuses = [@status] + @context[:ancestors] + @context[:descendants]
|
||||
|
||||
set_maps(statuses)
|
||||
set_counters_maps(statuses)
|
||||
# set_counters_maps(statuses)
|
||||
end
|
||||
|
||||
def card
|
||||
|
@ -36,7 +36,7 @@ class Api::V1::StatusesController < ApiController
|
|||
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)
|
||||
# set_account_counters_maps(@accounts)
|
||||
|
||||
next_path = reblogged_by_api_v1_status_url(max_id: results.last.id) if results.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
|
||||
|
@ -51,7 +51,7 @@ class Api::V1::StatusesController < 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 = favourited_by_api_v1_status_url(max_id: results.last.id) if results.size == limit_param(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