changeset 141:88d7a7714d4e

Restrict to just the fetch process
author nanaya <me@nanaya.pro>
date Wed, 13 Dec 2017 04:31:31 +0900
parents bef9b0c1d273
children 2d873f57f424
files app/models/tweet.rb
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/app/models/tweet.rb	Wed Dec 13 04:22:11 2017 +0900
+++ b/app/models/tweet.rb	Wed Dec 13 04:31:31 2017 +0900
@@ -21,13 +21,7 @@
     @timeline ||=
       Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => cache_expires_time) do
         begin
-          client.user_timeline(@twitter_id, TIMELINE_OPTIONS).select do |tweet|
-            tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
-          end.map do |tweet|
-            # Fails when there's Twitter::NullObject initiated somewhere in previous select
-            # Reference: https://github.com/sferik/twitter/issues/892
-            tweet.to_h
-          end
+          timeline = client.user_timeline(@twitter_id, TIMELINE_OPTIONS)
         rescue Twitter::Error::TooManyRequests
           @client_config_id += 1
 
@@ -37,6 +31,14 @@
             retry
           end
         end
+
+        timeline.select do |tweet|
+          tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
+        end.map do |tweet|
+          # Fails when there's Twitter::NullObject initiated somewhere in previous select
+          # Reference: https://github.com/sferik/twitter/issues/892
+          tweet.to_h
+        end
       end.map do |tweet_hash|
         Twitter::Tweet.new(tweet_hash)
       end