-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetcher.rb
36 lines (29 loc) · 1.08 KB
/
fetcher.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Fetcher
# These feeds are kind of expensive, so let's only generate them every 15
# minutes
TIME_TO_LIVE = 900
def initialize(actor_url)
# This used to support Atom feeds, and I would always accidentally use RSS
# instead so maybe other people have too. Either way, both those options are
# dead now (at least for Mastodon), so we'll assume that those feeds are
# content-negotiated in the same way that the ActivityPub Actor resource is—
# that is, they're all the same URL with different extensions (or Accept
# headers).
@actor_url = actor_url.sub(/\.(rss|atom)$/, '')
end
def call
generated_feed = CACHE.get("feed:#{actor_url}")
feed_fetched = CACHE.get("fetched:#{actor_url}").to_i
unless generated_feed and (Time.now.to_i - feed_fetched) < TIME_TO_LIVE
generated_feed = Generator.call(actor_url)
CACHE.set("feed:#{actor_url}", generated_feed)
CACHE.set("fetched:#{actor_url}", Time.now.to_i)
end
generated_feed
end
def self.call(*args)
new(*args).call
end
private
attr_reader :actor_url
end