mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-23 02:45:12 -05:00
Some checks failed
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Crowdin / Upload translations / upload-translations (push) Has been cancelled
Co-authored-by: David Roetzel <david@roetzel.de>
61 lines
1.4 KiB
Ruby
61 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Trends::Base
|
|
include Redisable
|
|
include LanguagesHelper
|
|
|
|
class_attribute :default_options
|
|
|
|
attr_reader :options
|
|
|
|
# @param [Hash] options
|
|
# @option options [Integer] :threshold Minimum amount of uses by unique accounts to begin calculating the score
|
|
# @option options [Integer] :review_threshold Minimum rank (lower = better) before requesting a review
|
|
# @option options [ActiveSupport::Duration] :max_score_cooldown For this amount of time, the peak score (if bigger than current score) is decayed-from
|
|
# @option options [ActiveSupport::Duration] :max_score_halflife How quickly a peak score decays
|
|
def initialize(options = {})
|
|
@options = self.class.default_options.merge(options)
|
|
end
|
|
|
|
def register(_status)
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def add(*)
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def refresh(*)
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def request_review
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def query
|
|
Trends::Query.new(klass)
|
|
end
|
|
|
|
protected
|
|
|
|
def key_prefix
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def recently_used_ids(at_time = Time.now.utc)
|
|
redis.smembers(used_key(at_time)).map(&:to_i)
|
|
end
|
|
|
|
def record_used_id(id, at_time = Time.now.utc)
|
|
redis.sadd(used_key(at_time), id)
|
|
redis.expire(used_key(at_time), 1.day.seconds)
|
|
end
|
|
|
|
private
|
|
|
|
def used_key(at_time)
|
|
"#{key_prefix}:used:#{at_time.beginning_of_day.to_i}"
|
|
end
|
|
end
|