about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activity_tracker.rb31
-rw-r--r--app/lib/provider_discovery.rb2
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