Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37995 - High memory rendering Arf Report index page #584

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/controllers/arf_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ def model_of_controller
end

def index
# Avoid using includes() with nested associations and "order by" together. Otherwise,
# includes() will use join tables instead and Rails somehow create many objects and
# high memory consumption.
@arf_reports_pg = resource_base.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])
arf_report_ids = @arf_reports_pg.pluck(:id)
@arf_reports = resource_base.includes(:policy, :openscap_proxy, :host => %i[policies last_report_object host_statuses])
.search_for(params[:search], :order => params[:order])
.paginate(:page => params[:page], :per_page => params[:per_page])
.where(id: arf_report_ids)
.sort_by { |arf_report| arf_report_ids.index(arf_report.id) }
end

def show
Expand Down
2 changes: 1 addition & 1 deletion app/views/arf_reports/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
</div>
</div>
</div>
<%= will_paginate_with_info @arf_reports %>
<%= will_paginate_with_info @arf_reports_pg %>
Loading