]> git.openstreetmap.org Git - rails.git/commitdiff
Make "include" and "limit" keyword args of pagination method
authorAnton Khorev <tony29@yandex.ru>
Tue, 26 Mar 2024 01:20:59 +0000 (04:20 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 26 Mar 2024 01:41:07 +0000 (04:41 +0300)
app/controllers/concerns/pagination_methods.rb
app/controllers/diary_entries_controller.rb
app/controllers/traces_controller.rb

index 58b522516618c545a2d1429aaba5675539d51dba..3dc9f52aad3057726c69435227ec381a3fe808f0 100644 (file)
@@ -5,7 +5,7 @@ module PaginationMethods
 
   ##
   # limit selected items to one page, get ids of first item before/after the page
-  def get_page_items(items, includes)
+  def get_page_items(items, includes: [], limit: 20)
     id_column = "#{items.table_name}.id"
     page_items = if params[:before]
                    items.where("#{id_column} < ?", params[:before]).order(:id => :desc)
@@ -15,7 +15,7 @@ module PaginationMethods
                    items.order(:id => :desc)
                  end
 
-    page_items = page_items.limit(20)
+    page_items = page_items.limit(limit)
     page_items = page_items.includes(includes)
     page_items = page_items.sort.reverse
 
index ff668644894e9e2a972809c4d0fd7b20e94bf51a..8da0842eb09cbee7942cf28d725d5ee6b49e9308 100644 (file)
@@ -58,7 +58,7 @@ class DiaryEntriesController < ApplicationController
 
     @params = params.permit(:display_name, :friends, :nearby, :language)
 
-    @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, [:user, :language])
+    @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, :includes => [:user, :language])
   end
 
   def show
@@ -247,7 +247,7 @@ class DiaryEntriesController < ApplicationController
 
     @params = params.permit(:display_name, :before, :after)
 
-    @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, [:user])
+    @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user])
   end
 
   private
index 3539b6032a35624911725b11ba9fc5fdd6591f4f..42aea82999e4856d822d15a2ef4cac7feb894986 100644 (file)
@@ -61,7 +61,7 @@ class TracesController < ApplicationController
 
     @params = params.permit(:display_name, :tag, :before, :after)
 
-    @traces, @newer_traces_id, @older_traces_id = get_page_items(traces, [:user, :tags])
+    @traces, @newer_traces_id, @older_traces_id = get_page_items(traces, :includes => [:user, :tags])
 
     # final helper vars for view
     @target_user = target_user