Small optimizations in Atom feeds

This commit is contained in:
Eugen Rochko 2016-03-21 10:31:20 +01:00
parent 19a259915e
commit 7e00a21ea6
5 changed files with 6 additions and 4 deletions

View file

@ -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 format.atom { @entries = @account.stream_entries.order('id desc').with_includes }
end end
end end

View file

@ -40,7 +40,7 @@ module AtomBuilderHelper
end end
def title(xml, title) def title(xml, title)
xml.title title xml.title strip_tags(title || '').truncate(80)
end end
def author(xml, &block) def author(xml, &block)

View file

@ -46,7 +46,7 @@ class Status < ActiveRecord::Base
end end
def title def title
content.truncate(80, omission: "...") content
end end
def reblogs_count def reblogs_count

View file

@ -4,6 +4,8 @@ class StreamEntry < ActiveRecord::Base
validates :account, :activity, presence: true validates :account, :activity, presence: true
scope :with_includes, -> { includes(:activity) }
def object_type def object_type
orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type) orphaned? ? :activity : (targeted? ? :activity : self.activity.object_type)
end end

View file

@ -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)
@account.stream_entries.order('id desc').each do |stream_entry| @entries.order('id desc').each do |stream_entry|
entry(xml, false) do entry(xml, false) do
include_entry xml, stream_entry include_entry xml, stream_entry
end end