diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2018-05-27 21:45:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-27 21:45:30 +0200 |
commit | 9bd23dc4e51ba47283a8e3a66cd94b4e624a5235 (patch) | |
tree | 119802887a7b894ea3aac5e28a8a7a15524c1c35 /app/models/tag.rb | |
parent | 63c7b9157274f57c496399a1a5c728b32415034c (diff) |
Track trending tags (#7638)
* Track trending tags - Half-life of 1 day - Historical usage in daily buckets (last 7 days stored) - GET /api/v1/trends Fix #271 * Add trends to web UI * Don't render compose form on search route, adjust search results header * Disqualify tag from trends if it's in disallowed hashtags setting * Count distinct accounts using tag, ignore silenced accounts
Diffstat (limited to 'app/models/tag.rb')
-rw-r--r-- | app/models/tag.rb | 16 |
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) + '%' |