Commit 4195f33b authored by Alexandru Croitor's avatar Alexandru Croitor

Optimise events count sql

Improve events count sql by removing the extra joins
that make the sql slower as much more data is loaded
even though not needed.
parent 7be3f599
...@@ -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