Commit 4957dd4a authored by Kerri Miller's avatar Kerri Miller

Merge branch 'attempt_to_optimise_events_count_sql' into 'master'

Optimise events count sql and pagination

See merge request gitlab-org/gitlab!74062
parents d43aebe1 4195f33b
...@@ -44,7 +44,6 @@ class EventsFinder ...@@ -44,7 +44,6 @@ class EventsFinder
events = by_created_at_after(events) events = by_created_at_after(events)
events = sort(events) events = sort(events)
events = events.with_associations if params[:with_associations]
paginated_filtered_by_user_visibility(events) paginated_filtered_by_user_visibility(events)
end end
...@@ -113,10 +112,12 @@ class EventsFinder ...@@ -113,10 +112,12 @@ class EventsFinder
end end
def paginated_filtered_by_user_visibility(events) def paginated_filtered_by_user_visibility(events)
events_count = events.count
events = events.with_associations if params[:with_associations]
limited_events = events.page(page).per(per_page) limited_events = events.page(page).per(per_page)
visible_events = limited_events.select { |event| event.visible_to_user?(current_user) } visible_events = limited_events.select { |event| event.visible_to_user?(current_user) }
Kaminari.paginate_array(visible_events, total_count: events.count) Kaminari.paginate_array(visible_events, total_count: events_count)
end end
def per_page def per_page
......
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