about summary refs log tree commit diff
path: root/app/controllers/api/v1/instances/activity_controller.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-10-14 22:57:41 +0200
committerGitHub <noreply@github.com>2021-10-14 22:57:41 +0200
commitb6f24ef0fb8b594c38c29090518c21af051b63b7 (patch)
tree5cec6a6b13dfd062848c74ae8e041c589ae40d00 /app/controllers/api/v1/instances/activity_controller.rb
parentebf2c3195615bb524f6908e84f99887c8775cbc3 (diff)
parent6964952d5f242ca936de9df361185b3e70a99ca4 (diff)
Merge pull request #1622 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/api/v1/instances/activity_controller.rb')
-rw-r--r--app/controllers/api/v1/instances/activity_controller.rb27
1 files changed, 13 insertions, 14 deletions
diff --git a/app/controllers/api/v1/instances/activity_controller.rb b/app/controllers/api/v1/instances/activity_controller.rb
index 4f6b4bcbf..bad61425a 100644
--- a/app/controllers/api/v1/instances/activity_controller.rb
+++ b/app/controllers/api/v1/instances/activity_controller.rb
@@ -14,22 +14,21 @@ class Api::V1::Instances::ActivityController < Api::BaseController
   private
 
   def activity
-    weeks = []
-
-    12.times do |i|
-      day     = i.weeks.ago.to_date
-      week_id = day.cweek
-      week    = Date.commercial(day.cwyear, week_id)
-
-      weeks << {
-        week: week.to_time.to_i.to_s,
-        statuses: Redis.current.get("activity:statuses:local:#{week_id}") || '0',
-        logins: Redis.current.pfcount("activity:logins:#{week_id}").to_s,
-        registrations: Redis.current.get("activity:accounts:local:#{week_id}") || '0',
+    statuses_tracker      = ActivityTracker.new('activity:statuses:local', :basic)
+    logins_tracker        = ActivityTracker.new('activity:logins', :unique)
+    registrations_tracker = ActivityTracker.new('activity:accounts:local', :basic)
+
+    (0...12).map do |i|
+      start_of_week = i.weeks.ago
+      end_of_week   = start_of_week + 6.days
+
+      {
+        week: start_of_week.to_i.to_s,
+        statuses: statuses_tracker.sum(start_of_week, end_of_week).to_s,
+        logins: logins_tracker.sum(start_of_week, end_of_week).to_s,
+        registrations: registrations_tracker.sum(start_of_week, end_of_week).to_s,
       }
     end
-
-    weeks
   end
 
   def require_enabled_api!