# HG changeset patch # User nanaya # Date 1469645348 -32400 # Node ID 0c8a8b3901458d482cb8145cfda95ea7628a9749 # Parent 5cc4aab05c55282ad07e271fc4034b7396ca3f9b Now with epic caching And kicking out builder because I can't figure out how to cache it ;_; diff -r 5cc4aab05c55 -r 0c8a8b390145 app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb Thu Jul 28 01:54:54 2016 +0900 +++ b/app/helpers/application_helper.rb Thu Jul 28 03:49:08 2016 +0900 @@ -8,4 +8,8 @@ "#{text.first(limit)}..." end end + + def atom_id(id) + "tag:#{request.host_with_port},2005:#{id}" + end end diff -r 5cc4aab05c55 -r 0c8a8b390145 app/views/tweets/_tweet.atom.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/tweets/_tweet.atom.erb Thu Jul 28 03:49:08 2016 +0900 @@ -0,0 +1,13 @@ + + <%= atom_id "#{tweet.user.id}/#{tweet.id}" %> + <%= tweet.created_at %> + <%= tweet.created_at %> + + <%= ellipsize tweet.text %> + + <%= render(:partial => "tweet", :formats => :html, :locals => { :tweet => tweet }).to_str %> + + + <%= tweet.user.screen_name %> + + diff -r 5cc4aab05c55 -r 0c8a8b390145 app/views/tweets/show.atom.builder --- a/app/views/tweets/show.atom.builder Thu Jul 28 01:54:54 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -atom_feed do |feed| - feed.title "#{@user.name} (@#{@user.screen_name})" - feed.icon @user.profile_image_url_https - feed.updated @tweets.first.try(:created_at) || Time.at(0) - - @tweets.each do |tweet| - feed.entry tweet, :url => tweet.uri, :updated => tweet.created_at do |entry| - entry.title ellipsize(tweet.text) - entry.content render(:partial => "tweet", :formats => :html, :locals => { :tweet => tweet }), :type => "html" - entry.author do |author| - author.name tweet.user.screen_name - end - end - end -end diff -r 5cc4aab05c55 -r 0c8a8b390145 app/views/tweets/show.atom.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/tweets/show.atom.erb Thu Jul 28 03:49:08 2016 +0900 @@ -0,0 +1,21 @@ + + + + tag:<%= request.host_with_port %>,2005:<%= @user.id %> + + + + + + + <%= @user.name %> (<%= @user.screen_name %>) + + + <%= @user.profile_image_url_https %> + + + <%= @tweets.first.try(:created_at) || Time.at(0) %> + + + <%= render(:partial => "tweet", :collection => @tweets, :cached => ->(f) { f.id }) %> + diff -r 5cc4aab05c55 -r 0c8a8b390145 config/initializers/monkeypatch_collection_cache_key_callable.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/initializers/monkeypatch_collection_cache_key_callable.rb Thu Jul 28 03:49:08 2016 +0900 @@ -0,0 +1,20 @@ +# stolen from https://github.com/rails/rails/pull/25616 + +if Gem::Version.new(Rails.version) >= Gem::Version.new("5.1.0") + raise "remove this monkey patch!" +end + +module ActionView::CollectionCaching + private def collection_by_cache_keys + seed = + if @options[:cached].respond_to?(:call) + @options[:cached] + else + ->(i) { i } + end + + @collection.each_with_object({}) do |item, hash| + hash[expanded_cache_key(seed.call(item))] = item + end + end +end