comparison 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
comparison
equal deleted inserted replaced
140:bef9b0c1d273 141:88d7a7714d4e
19 initial_config_id = client_config_id 19 initial_config_id = client_config_id
20 20
21 @timeline ||= 21 @timeline ||=
22 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => cache_expires_time) do 22 Rails.cache.fetch({ :timeline => @twitter_id }, :expires_in => cache_expires_time) do
23 begin 23 begin
24 client.user_timeline(@twitter_id, TIMELINE_OPTIONS).select do |tweet| 24 timeline = client.user_timeline(@twitter_id, TIMELINE_OPTIONS)
25 tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
26 end.map do |tweet|
27 # Fails when there's Twitter::NullObject initiated somewhere in previous select
28 # Reference: https://github.com/sferik/twitter/issues/892
29 tweet.to_h
30 end
31 rescue Twitter::Error::TooManyRequests 25 rescue Twitter::Error::TooManyRequests
32 @client_config_id += 1 26 @client_config_id += 1
33 27
34 if initial_config_id == client_config_id 28 if initial_config_id == client_config_id
35 raise 29 raise
36 else 30 else
37 retry 31 retry
38 end 32 end
33 end
34
35 timeline.select do |tweet|
36 tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
37 end.map do |tweet|
38 # Fails when there's Twitter::NullObject initiated somewhere in previous select
39 # Reference: https://github.com/sferik/twitter/issues/892
40 tweet.to_h
39 end 41 end
40 end.map do |tweet_hash| 42 end.map do |tweet_hash|
41 Twitter::Tweet.new(tweet_hash) 43 Twitter::Tweet.new(tweet_hash)
42 end 44 end
43 end 45 end