diff options
author | David Yip <yipdw@member.fsf.org> | 2017-12-30 18:24:38 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-30 18:24:38 -0600 |
commit | d817c0a958efda990af654f72d15d6f42b43dd49 (patch) | |
tree | 0cff3632163fadeba3585f56ecdd8d1d919e12c7 /app/lib | |
parent | 65c87ca0ae20eb5dc62751047bda3e8b11e37ce0 (diff) | |
parent | 4cca1d1e7efce51eecb64489f412a7b8631f0aed (diff) |
Merge pull request #291 from glitch-soc/merge-upstream
Merge with upstream @ f4b80e6511f21b60f71ed182bb66ca6ef0ba9f66
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activity_tracker.rb | 31 | ||||
-rw-r--r-- | app/lib/provider_discovery.rb | 2 |
2 files changed, 32 insertions, 1 deletions
diff --git a/app/lib/activity_tracker.rb b/app/lib/activity_tracker.rb new file mode 100644 index 000000000..50e927b0c --- /dev/null +++ b/app/lib/activity_tracker.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class ActivityTracker + EXPIRE_AFTER = 90.days.seconds + + class << self + def increment(prefix) + key = [prefix, current_week].join(':') + + redis.incrby(key, 1) + redis.expire(key, EXPIRE_AFTER) + end + + def record(prefix, value) + key = [prefix, current_week].join(':') + + redis.pfadd(key, value) + redis.expire(key, value) + end + + private + + def redis + Redis.current + end + + def current_week + Time.zone.today.cweek + end + end +end diff --git a/app/lib/provider_discovery.rb b/app/lib/provider_discovery.rb index 04ba38101..5732e4fcb 100644 --- a/app/lib/provider_discovery.rb +++ b/app/lib/provider_discovery.rb @@ -29,7 +29,7 @@ class ProviderDiscovery < OEmbed::ProviderDiscovery end if format.nil? || format == :xml - provider_endpoint ||= html.at_xpath('//link[@type="application/xml+oembed"]')&.attribute('href')&.value + provider_endpoint ||= html.at_xpath('//link[@type="text/xml+oembed"]')&.attribute('href')&.value format ||= :xml if provider_endpoint end |