From 082e1cbe5a6bcff291e0fe96260ca8920776a18e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 22 Mar 2016 21:53:33 +0100 Subject: [PATCH] Fix default max_id query in paginate_by_max_id --- app/controllers/api/accounts_controller.rb | 2 +- app/models/status.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/accounts_controller.rb b/app/controllers/api/accounts_controller.rb index 5bac98f81..8c4da5270 100644 --- a/app/controllers/api/accounts_controller.rb +++ b/app/controllers/api/accounts_controller.rb @@ -15,7 +15,7 @@ class Api::AccountsController < ApiController end def statuses - @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id]) + @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id] || nil) end def follow diff --git a/app/models/status.rb b/app/models/status.rb index f1c12383b..68f4adf34 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -17,7 +17,7 @@ class Status < ActiveRecord::Base scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') } scope :with_includes, -> { includes(:account, reblog: :account, thread: :account) } - scope :paginate_by_max_id, -> (limit, max_id) { order('id desc').limit(limit).where('id < ?', max_id) } + scope :paginate_by_max_id, -> (limit, max_id) { order('id desc').limit(limit).where(max_id.nil? ? '1=1' : ['id < ?', max_id]) } def local? self.uri.nil?