about summary refs log tree commit diff
path: root/app/models/tag.rb
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-05-29 13:52:26 +0200
committerThibaut Girka <thib@sitedethib.com>2018-05-29 13:52:26 +0200
commitc087738270e7fb16b1d284e8dd72cf99b4238bb8 (patch)
tree23327fe190fd90589c9dc8d64e96fcf0b7d28ddd /app/models/tag.rb
parent8b98afa781018bc7cfdb325f6b1fca0b1edcd8cb (diff)
parent90908fc24ba57c877de75fe117b8cc234e29d4f0 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models/tag.rb')
-rw-r--r--app/models/tag.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 8b1b02412..4f31f796e 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -21,6 +21,22 @@ class Tag < ApplicationRecord
     name
   end
 
+  def history
+    days = []
+
+    7.times do |i|
+      day = i.days.ago.beginning_of_day.to_i
+
+      days << {
+        day: day.to_s,
+        uses: Redis.current.get("activity:tags:#{id}:#{day}") || '0',
+        accounts: Redis.current.pfcount("activity:tags:#{id}:#{day}:accounts").to_s,
+      }
+    end
+
+    days
+  end
+
   class << self
     def search_for(term, limit = 5)
       pattern = sanitize_sql_like(term.strip) + '%'