]> cat aescling's git repositories - mastodon.git/commitdiff
Limit Atom feeds to 20 items by default, add pagination by max_id
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 24 Mar 2016 11:49:34 +0000 (12:49 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 24 Mar 2016 11:49:34 +0000 (12:49 +0100)
(But there are no Atom feed pagination elements yet)

app/controllers/accounts_controller.rb
app/models/stream_entry.rb
app/views/accounts/show.atom.ruby

index cfccd0f1972dfcff922153f61306788dcf48d710..53f665238f4e9c39b499911471eba821944f0eb5 100644 (file)
@@ -7,7 +7,7 @@ class AccountsController < ApplicationController
   def show
     respond_to do |format|
       format.html { @statuses = @account.statuses.order('id desc').with_includes.with_counters.paginate(page: params[:page], per_page: 10)}
-      format.atom { @entries  = @account.stream_entries.order('id desc').with_includes }
+      format.atom { @entries  = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id] || nil) }
     end
   end
 
index 68a33ccf70870d214bc8ad2f4ca6f9e57ca50589..d64edd62fe9bd375c54f4816fa141edc04f34d7d 100644 (file)
@@ -4,7 +4,8 @@ class StreamEntry < ActiveRecord::Base
 
   validates :account, :activity, presence: true
 
-  scope :with_includes, -> { includes(:activity) }
+  scope :with_includes,      -> { includes(:activity) }
+  scope :paginate_by_max_id, -> (limit, max_id) { order('id desc').limit(limit).where(max_id.nil? ? '1=1' : ['id < ?', max_id]) }
 
   def object_type
     orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)
index e2ae57cc454492554773d4fa18c24a2552ff4286..b7e3d259045dd011c6bb4b7a0b04ed424f1a1e2c 100644 (file)
@@ -15,7 +15,7 @@ Nokogiri::XML::Builder.new do |xml|
     link_hub       xml, Rails.configuration.x.hub_url
     link_salmon    xml, api_salmon_url(@account.id)
 
-    @entries.order('id desc').each do |stream_entry|
+    @entries.each do |stream_entry|
       entry(xml, false) do
         include_entry xml, stream_entry
       end