]> cat aescling's git repositories - mastodon.git/commitdiff
Fix dangling language-specific trends (#17997)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 8 Apr 2022 17:35:31 +0000 (19:35 +0200)
committerGitHub <noreply@github.com>
Fri, 8 Apr 2022 17:35:31 +0000 (19:35 +0200)
- Change score half-life for trending statuses from 2 to 6 hours
- Change score threshold for trimming old items from 1 to 0.3

app/models/trends/base.rb
app/models/trends/links.rb
app/models/trends/statuses.rb

index 38a49246b7e8a65425a9135e2a5c1b9fc555ab70..200f8d63588a32e78d3b0854b69cd2d4839f2743 100644 (file)
@@ -65,8 +65,8 @@ class Trends::Base
   end
 
   def trim_older_items
-    redis.zremrangebyscore("#{key_prefix}:all", '-inf', '(1')
-    redis.zremrangebyscore("#{key_prefix}:allowed", '-inf', '(1')
+    redis.zremrangebyscore("#{key_prefix}:all", '-inf', '(0.3')
+    redis.zremrangebyscore("#{key_prefix}:allowed", '-inf', '(0.3')
   end
 
   def score_at_rank(rank)
index 62308e7067bbade3ff1efe8c60b708df9da5793d..5f046643a0a6f46866f66c27c85831d3ca18acc6 100644 (file)
@@ -30,7 +30,6 @@ class Trends::Links < Trends::Base
   def refresh(at_time = Time.now.utc)
     preview_cards = PreviewCard.where(id: (recently_used_ids(at_time) + currently_trending_ids(false, -1)).uniq)
     calculate_scores(preview_cards, at_time)
-    trim_older_items
   end
 
   def request_review
@@ -101,6 +100,8 @@ class Trends::Links < Trends::Base
       })
     end
 
+    trim_older_items
+
     # Clean up localized sets by calculating the intersection with the main
     # set. We do this instead of just deleting the localized sets to avoid
     # having moments where the API returns empty results
@@ -108,7 +109,7 @@ class Trends::Links < Trends::Base
     redis.pipelined do
       Trends.available_locales.each do |locale|
         redis.zinterstore("#{key_prefix}:all:#{locale}", ["#{key_prefix}:all:#{locale}", "#{key_prefix}:all"], aggregate: 'max')
-        redis.zinterstore("#{key_prefix}:allowed:#{locale}", ["#{key_prefix}:allowed:#{locale}", "#{key_prefix}:all"], aggregate: 'max')
+        redis.zinterstore("#{key_prefix}:allowed:#{locale}", ["#{key_prefix}:allowed:#{locale}", "#{key_prefix}:allowed"], aggregate: 'max')
       end
     end
   end
index dc5309554cc0f4d02468a0bf7f2122a7b663bc39..d9b07446ef23876acbef80c99d4514da610675e9 100644 (file)
@@ -6,7 +6,7 @@ class Trends::Statuses < Trends::Base
   self.default_options = {
     threshold: 5,
     review_threshold: 3,
-    score_halflife: 2.hours.freeze,
+    score_halflife: 6.hours.freeze,
   }
 
   class Query < Trends::Query
@@ -48,7 +48,6 @@ class Trends::Statuses < Trends::Base
   def refresh(at_time = Time.now.utc)
     statuses = Status.where(id: (recently_used_ids(at_time) + currently_trending_ids(false, -1)).uniq).includes(:account, :media_attachments)
     calculate_scores(statuses, at_time)
-    trim_older_items
   end
 
   def request_review
@@ -111,13 +110,15 @@ class Trends::Statuses < Trends::Base
         })
       end
 
+      trim_older_items
+
       # Clean up localized sets by calculating the intersection with the main
       # set. We do this instead of just deleting the localized sets to avoid
       # having moments where the API returns empty results
 
       Trends.available_locales.each do |locale|
         redis.zinterstore("#{key_prefix}:all:#{locale}", ["#{key_prefix}:all:#{locale}", "#{key_prefix}:all"], aggregate: 'max')
-        redis.zinterstore("#{key_prefix}:allowed:#{locale}", ["#{key_prefix}:allowed:#{locale}", "#{key_prefix}:all"], aggregate: 'max')
+        redis.zinterstore("#{key_prefix}:allowed:#{locale}", ["#{key_prefix}:allowed:#{locale}", "#{key_prefix}:allowed"], aggregate: 'max')
       end
     end
   end