Commit 83676af4 authored by manojmj's avatar manojmj

Use without_count for records paginated with paginate_without_counts

This change adds .without_count to queries of records
that will be paginated using paginate_without_counts,
so that a count query is not triggered during pagination.
parent d2f99986
...@@ -9,7 +9,8 @@ class Admin::AuditLogsController < Admin::ApplicationController ...@@ -9,7 +9,8 @@ class Admin::AuditLogsController < Admin::ApplicationController
PER_PAGE = 25 PER_PAGE = 25
def index def index
@events = AuditLogFinder.new(audit_logs_params).execute.page(params[:page]).per(PER_PAGE) @events = audit_log_events.page(params[:page]).per(PER_PAGE).without_count
@entity = case audit_logs_params[:entity_type] @entity = case audit_logs_params[:entity_type]
when 'User' when 'User'
User.find_by_id(audit_logs_params[:entity_id]) User.find_by_id(audit_logs_params[:entity_id])
...@@ -24,6 +25,10 @@ class Admin::AuditLogsController < Admin::ApplicationController ...@@ -24,6 +25,10 @@ class Admin::AuditLogsController < Admin::ApplicationController
private private
def audit_log_events
AuditLogFinder.new(audit_logs_params).execute
end
def check_license_admin_audit_log_available! def check_license_admin_audit_log_available!
render_404 unless License.feature_available?(:admin_audit_log) render_404 unless License.feature_available?(:admin_audit_log)
end end
......
---
title: Do not trigger count query for pagination without count
merge_request: 21232
author:
type: performance
# frozen_string_literal: true
require 'spec_helper'
describe Admin::AuditLogsController do
let(:admin) { create(:admin) }
describe 'GET #index' do
before do
sign_in(admin)
end
context 'licensed' do
before do
stub_licensed_features(admin_audit_log: true)
end
context 'pagination' do
it 'paginates audit events, without casting a count query' do
create(:user_audit_event, created_at: 5.days.ago)
get :index, params: { 'entity_type': 'User' }
expect(assigns(:events)).to be_kind_of(Kaminari::PaginatableWithoutCount)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment