Mercurial > rsstweet
diff app/models/tweet.rb @ 141:88d7a7714d4e
Restrict to just the fetch process
author | nanaya <me@nanaya.pro> |
---|---|
date | Wed, 13 Dec 2017 04:31:31 +0900 |
parents | 7907fe886675 |
children | 2d873f57f424 |
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