Skip to content

Commit

Permalink
RSS feed optimizations (#1752)
Browse files Browse the repository at this point in the history
* RSS feed optimizations

* Update app/views/articles/feed.rss.builder

Co-Authored-By: benhalpern <bendhalpern@gmail.com>

* Update app/controllers/articles_controller.rb

* Update app/controllers/articles_controller.rb
  • Loading branch information
benhalpern committed Feb 7, 2019
1 parent 9c0bfd6 commit 7d6c85a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 6 additions & 7 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ def feed
if params[:username]
if @user = User.find_by_username(params[:username])
@articles = Article.where(published: true, user_id: @user.id).
includes(:user).
select(:published_at, :slug, :processed_html, :user_id, :organization_id, :title).
select(:published_at, :processed_html, :user_id, :organization_id, :title, :path).
order("published_at DESC").
page(@page).per(15)
page(@page).per(12)
elsif @user = Organization.find_by_slug(params[:username])
@articles = Article.where(published: true, organization_id: @user.id).
includes(:user).
select(:published_at, :slug, :processed_html, :user_id, :organization_id, :title).
select(:published_at, :processed_html, :user_id, :organization_id, :title, :path).
order("published_at DESC").
page(@page).per(15)
page(@page).per(12)
else
render body: nil
return
end
else
@articles = Article.where(published: true, featured: true).
includes(:user).
select(:published_at, :slug, :processed_html, :user_id, :organization_id, :title).
select(:published_at, :processed_html, :user_id, :organization_id, :title, :path).
order("published_at DESC").
page(@page).per(15)
page(@page).per(12)
end
set_surrogate_key_header "feed", @articles.map(&:record_key)
response.headers["Surrogate-Control"] = "max-age=600, stale-while-revalidate=30, stale-if-error=86400"
Expand Down
12 changes: 4 additions & 8 deletions app/views/articles/feed.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ xml.rss version: "2.0" do

@articles.each do |article|
xml.item do
if article.title
xml.title article.title
else
xml.title ""
end
xml.author article.user.name
xml.title article.title
xml.author (@user && @user.class.name == "User") ? @user.name : article.user.name
xml.pubDate article.published_at.to_s(:rfc822) if article.published_at
xml.link "https://dev.to/#{article.username}/#{article.slug}"
xml.guid "https://dev.to/#{article.username}/#{article.slug}"
xml.link "https://dev.to/#{article.path}"
xml.guid "https://dev.to/#{article.path}"
xml.description sanitize article.processed_html.html_safe,
tags: %w(strong em a table tbody thead tfoot th tr td col colgroup del p h1 h2 h3 h4 h5 h6 blockquote iframe time div span i em u b ul ol li dd dl dt q code pre img sup cite center br small),
attributes: %w(href strong em class ref rel src title alt colspan height width size rowspan span value start data-conversation data-lang id)
Expand Down

0 comments on commit 7d6c85a

Please sign in to comment.