Limit Atom feeds to 20 items by default, add pagination by max_id
(But there are no Atom feed pagination elements yet)
This commit is contained in:
		
							parent
							
								
									c8999a116e
								
							
						
					
					
						commit
						7e58303a8d
					
				| 
						 | 
					@ -7,7 +7,7 @@ class AccountsController < ApplicationController
 | 
				
			||||||
  def show
 | 
					  def show
 | 
				
			||||||
    respond_to do |format|
 | 
					    respond_to do |format|
 | 
				
			||||||
      format.html { @statuses = @account.statuses.order('id desc').with_includes.with_counters.paginate(page: params[:page], per_page: 10)}
 | 
					      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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,7 +4,8 @@ class StreamEntry < ActiveRecord::Base
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  validates :account, :activity, presence: true
 | 
					  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
 | 
					  def object_type
 | 
				
			||||||
    orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)
 | 
					    orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ Nokogiri::XML::Builder.new do |xml|
 | 
				
			||||||
    link_hub       xml, Rails.configuration.x.hub_url
 | 
					    link_hub       xml, Rails.configuration.x.hub_url
 | 
				
			||||||
    link_salmon    xml, api_salmon_url(@account.id)
 | 
					    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
 | 
					      entry(xml, false) do
 | 
				
			||||||
        include_entry xml, stream_entry
 | 
					        include_entry xml, stream_entry
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue