diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-04-29 22:42:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-29 22:42:42 +0200 |
commit | 6476f7e4da4da7c353d497aae5a86fc3909ce532 (patch) | |
tree | c800ed4deac373a82298d962679c1bb066d261f0 /app/models/trends/tags.rb | |
parent | 5c691430e5f05524523bf32a3fce10633ec37092 (diff) |
Change trending statuses to only show one status from each account (#18181)
Calculate trends in temporary sets to avoid having to manage items that go below the decay threshold while not having any moments where a half-processed set is accessible to end-users
Diffstat (limited to 'app/models/trends/tags.rb')
-rw-r--r-- | app/models/trends/tags.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/app/models/trends/tags.rb b/app/models/trends/tags.rb index 3caa58815..19ade52ba 100644 --- a/app/models/trends/tags.rb +++ b/app/models/trends/tags.rb @@ -8,6 +8,7 @@ class Trends::Tags < Trends::Base review_threshold: 3, max_score_cooldown: 2.days.freeze, max_score_halflife: 4.hours.freeze, + decay_threshold: 1, } def register(status, at_time = Time.now.utc) @@ -26,7 +27,6 @@ class Trends::Tags < Trends::Base def refresh(at_time = Time.now.utc) tags = Tag.where(id: (recently_used_ids(at_time) + currently_trending_ids(false, -1)).uniq) calculate_scores(tags, at_time) - trim_older_items end def request_review @@ -53,6 +53,8 @@ class Trends::Tags < Trends::Base private def calculate_scores(tags, at_time) + items = [] + tags.each do |tag| expected = tag.history.get(at_time - 1.day).accounts.to_f expected = 1.0 if expected.zero? @@ -79,11 +81,16 @@ class Trends::Tags < Trends::Base decaying_score = max_score * (0.5**((at_time.to_f - max_time.to_f) / options[:max_score_halflife].to_f)) - add_to_and_remove_from_subsets(tag.id, decaying_score, { - all: true, - allowed: tag.trendable?, - }) + next unless decaying_score >= options[:decay_threshold] + + items << { score: decaying_score, item: tag } end + + replace_items('', items) + end + + def filter_for_allowed_items(items) + items.select { |item| item[:item].trendable? } end def would_be_trending?(id) |