Merge commit '877090518682b6c77ba9bdfa0231afd56daec44d' into glitch-soc/merge-upstream
Conflicts: - `app/models/concerns/user/has_settings.rb`: Not a real conflict, upstream added a setting textually close to a glitch-soc one. Added upstream's new setting. - `app/views/settings/preferences/appearance/show.html.haml`: Not a real conflict, upstream added a setting textually close to a glitch-soc one. Added upstream's new setting. - `config/routes.rb`: Upstream moved web app routes to `config/routes/web_app.rb`, while glitch-soc had an extra route. Moved the extra route to `config/routes/web_app.rb`. - `spec/controllers/settings/preferences/appearance_controller_spec.rb`: This spec got converted to a system spec upstream. However, the theme setting works differently in glitch-soc, so the spec had been changed. Changed the corresponding system spec as well.
This commit is contained in:
commit
0aa69487a2
759 files changed
+13447
-7221
No files matched your search
@@ -5,11 +5,11 @@
|
||||
# Table name: account_aliases
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# acct :string default(""), not null
|
||||
# uri :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class AccountAlias < ApplicationRecord
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
# Table name: account_conversations
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# conversation_id :bigint(8)
|
||||
# lock_version :integer default(0), not null
|
||||
# participant_account_ids :bigint(8) default([]), not null, is an Array
|
||||
# status_ids :bigint(8) default([]), not null, is an Array
|
||||
# last_status_id :bigint(8)
|
||||
# lock_version :integer default(0), not null
|
||||
# unread :boolean default(FALSE), not null
|
||||
# account_id :bigint(8) not null
|
||||
# conversation_id :bigint(8) not null
|
||||
# last_status_id :bigint(8)
|
||||
#
|
||||
|
||||
class AccountConversation < ApplicationRecord
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
# Table name: account_deletion_requests
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
class AccountDeletionRequest < ApplicationRecord
|
||||
DELAY_TO_DELETION = 30.days.freeze
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
# Table name: account_domain_blocks
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string
|
||||
# domain :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8)
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class AccountDomainBlock < ApplicationRecord
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
# Table name: account_notes
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# target_account_id :bigint(8)
|
||||
# comment :text not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# target_account_id :bigint(8) not null
|
||||
#
|
||||
class AccountNote < ApplicationRecord
|
||||
include RelationshipCacheable
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
# Table name: account_pins
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# target_account_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# target_account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class AccountPin < ApplicationRecord
|
||||
@@ -23,6 +23,6 @@ class AccountPin < ApplicationRecord
|
||||
private
|
||||
|
||||
def validate_follow_relationship
|
||||
errors.add(:base, I18n.t('accounts.pin_errors.following')) unless account.following?(target_account)
|
||||
errors.add(:base, I18n.t('accounts.pin_errors.following')) unless account&.following?(target_account)
|
||||
end
|
||||
end
|
||||
@@ -5,15 +5,15 @@
|
||||
# Table name: admin_action_logs
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# action :string default(""), not null
|
||||
# human_identifier :string
|
||||
# permalink :string
|
||||
# route_param :string
|
||||
# target_type :string
|
||||
# target_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# human_identifier :string
|
||||
# route_param :string
|
||||
# permalink :string
|
||||
# account_id :bigint(8) not null
|
||||
# target_id :bigint(8)
|
||||
#
|
||||
|
||||
class Admin::ActionLog < ApplicationRecord
|
||||
|
||||
@@ -57,6 +57,7 @@ class Admin::ActionLogFilter
|
||||
enable_relay: { target_type: 'Relay', action: 'enable' }.freeze,
|
||||
memorialize_account: { target_type: 'Account', action: 'memorialize' }.freeze,
|
||||
promote_user: { target_type: 'User', action: 'promote' }.freeze,
|
||||
publish_terms_of_service: { target_type: 'TermsOfService', action: 'publish' }.freeze,
|
||||
remove_avatar_user: { target_type: 'User', action: 'remove_avatar' }.freeze,
|
||||
reopen_report: { target_type: 'Report', action: 'reopen' }.freeze,
|
||||
resend_user: { target_type: 'User', action: 'resend' }.freeze,
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
# Table name: announcement_mutes
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# announcement_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# announcement_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class AnnouncementMute < ApplicationRecord
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
# Table name: announcement_reactions
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# announcement_id :bigint(8)
|
||||
# name :string default(""), not null
|
||||
# custom_emoji_id :bigint(8)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# announcement_id :bigint(8) not null
|
||||
# custom_emoji_id :bigint(8)
|
||||
#
|
||||
|
||||
class AnnouncementReaction < ApplicationRecord
|
||||
|
||||
@@ -51,6 +51,10 @@ module User::HasSettings
|
||||
settings['web.use_system_emoji_font']
|
||||
end
|
||||
|
||||
def setting_system_scrollbars_ui
|
||||
settings['web.use_system_scrollbars']
|
||||
end
|
||||
|
||||
def setting_noindex
|
||||
settings['noindex']
|
||||
end
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
# Table name: custom_filters
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# action :integer default("warn"), not null
|
||||
# context :string default([]), not null, is an Array
|
||||
# expires_at :datetime
|
||||
# phrase :text default(""), not null
|
||||
# context :string default([]), not null, is an Array
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# action :integer default("warn"), not null
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class CustomFilter < ApplicationRecord
|
||||
|
||||
@@ -47,7 +47,7 @@ class FeaturedTag < ApplicationRecord
|
||||
def decrement(deleted_status)
|
||||
if statuses_count <= 1
|
||||
update(statuses_count: 0, last_status_at: nil)
|
||||
elsif last_status_at > deleted_status.created_at
|
||||
elsif last_status_at.present? && last_status_at > deleted_status.created_at
|
||||
update(statuses_count: statuses_count - 1)
|
||||
else
|
||||
# Fetching the latest status creation time can be expensive, so only perform it
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
# Table name: markers
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# user_id :bigint(8)
|
||||
# timeline :string default(""), not null
|
||||
# last_read_id :bigint(8) default(0), not null
|
||||
# lock_version :integer default(0), not null
|
||||
# timeline :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# last_read_id :bigint(8) default(0), not null
|
||||
# user_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class Marker < ApplicationRecord
|
||||
|
||||
@@ -18,7 +18,7 @@ class Mention < ApplicationRecord
|
||||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validates :account, uniqueness: { scope: :status }
|
||||
validates :account_id, uniqueness: { scope: :status_id }
|
||||
|
||||
scope :active, -> { where(silent: false) }
|
||||
scope :silent, -> { where(silent: true) }
|
||||
|
||||
+8
-11
@@ -5,19 +5,19 @@
|
||||
# Table name: polls
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# status_id :bigint(8)
|
||||
# expires_at :datetime
|
||||
# options :string default([]), not null, is an Array
|
||||
# cached_tallies :bigint(8) default([]), not null, is an Array
|
||||
# multiple :boolean default(FALSE), not null
|
||||
# expires_at :datetime
|
||||
# hide_totals :boolean default(FALSE), not null
|
||||
# votes_count :bigint(8) default(0), not null
|
||||
# last_fetched_at :datetime
|
||||
# lock_version :integer default(0), not null
|
||||
# multiple :boolean default(FALSE), not null
|
||||
# options :string default([]), not null, is an Array
|
||||
# voters_count :bigint(8)
|
||||
# votes_count :bigint(8) default(0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# lock_version :integer default(0), not null
|
||||
# voters_count :bigint(8)
|
||||
# account_id :bigint(8) not null
|
||||
# status_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class Poll < ApplicationRecord
|
||||
@@ -39,9 +39,6 @@ class Poll < ApplicationRecord
|
||||
validates :expires_at, presence: true, if: :local?
|
||||
validates_with PollValidator, on: :create, if: :local?
|
||||
|
||||
scope :attached, -> { where.not(status_id: nil) }
|
||||
scope :unattached, -> { where(status_id: nil) }
|
||||
|
||||
before_validation :prepare_options, if: :local?
|
||||
before_validation :prepare_votes_count
|
||||
before_validation :prepare_cached_tallies
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
# Table name: poll_votes
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# poll_id :bigint(8)
|
||||
# choice :integer default(0), not null
|
||||
# uri :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# uri :string
|
||||
# account_id :bigint(8) not null
|
||||
# poll_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class PollVote < ApplicationRecord
|
||||
|
||||
@@ -134,7 +134,7 @@ class PreviewCard < ApplicationRecord
|
||||
end
|
||||
|
||||
def authors
|
||||
@authors ||= [PreviewCard::Author.new(self)]
|
||||
@authors ||= Array(serialized_authors)
|
||||
end
|
||||
|
||||
class Author < ActiveModelSerializers::Model
|
||||
@@ -169,6 +169,13 @@ class PreviewCard < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def serialized_authors
|
||||
if author_name? || author_url?
|
||||
PreviewCard::Author
|
||||
.new(self)
|
||||
end
|
||||
end
|
||||
|
||||
def extract_dimensions
|
||||
file = image.queued_for_write[:original]
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
# Table name: scheduled_statuses
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# scheduled_at :datetime
|
||||
# params :jsonb
|
||||
# scheduled_at :datetime
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class ScheduledStatus < ApplicationRecord
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
# id :bigint(8) not null, primary key
|
||||
# var :string not null
|
||||
# value :text
|
||||
# thing_type :string
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# thing_id :bigint(8)
|
||||
#
|
||||
|
||||
# This file is derived from a fork of the `rails-settings-cached` gem available at
|
||||
@@ -46,10 +44,10 @@ class Setting < ApplicationRecord
|
||||
after_commit :rewrite_cache, on: %i(create update)
|
||||
after_commit :expire_cache, on: %i(destroy)
|
||||
|
||||
# Settings are server-wide settings only, but they were previously
|
||||
# used for users too. This can be dropped later with a database
|
||||
# migration dropping any scoped setting.
|
||||
default_scope { where(thing_type: nil, thing_id: nil) }
|
||||
self.ignored_columns += %w(
|
||||
thing_id
|
||||
thing_type
|
||||
)
|
||||
|
||||
class << self
|
||||
# get or set a variable with the variable as the called method
|
||||
|
||||
@@ -32,6 +32,8 @@ class Tag < ApplicationRecord
|
||||
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
|
||||
has_many :followers, through: :passive_relationships, source: :account
|
||||
|
||||
has_one :trend, class_name: 'TagTrend', inverse_of: :tag, dependent: :destroy
|
||||
|
||||
HASHTAG_SEPARATORS = "_\u00B7\u30FB\u200c"
|
||||
HASHTAG_FIRST_SEQUENCE_CHUNK_ONE = "[[:word:]_][[:word:]#{HASHTAG_SEPARATORS}]*[[:alpha:]#{HASHTAG_SEPARATORS}]"
|
||||
HASHTAG_FIRST_SEQUENCE_CHUNK_TWO = "[[:word:]#{HASHTAG_SEPARATORS}]*[[:word:]_]"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: tag_trends
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# allowed :boolean default(FALSE), not null
|
||||
# language :string default(""), not null
|
||||
# rank :integer default(0), not null
|
||||
# score :float default(0.0), not null
|
||||
# tag_id :bigint(8) not null
|
||||
#
|
||||
class TagTrend < ApplicationRecord
|
||||
include RankedTrend
|
||||
|
||||
belongs_to :tag
|
||||
|
||||
scope :allowed, -> { where(allowed: true) }
|
||||
scope :not_allowed, -> { where(allowed: false) }
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: terms_of_services
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# changelog :text default(""), not null
|
||||
# notification_sent_at :datetime
|
||||
# published_at :datetime
|
||||
# text :text default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
class TermsOfService < ApplicationRecord
|
||||
scope :published, -> { where.not(published_at: nil).order(published_at: :desc) }
|
||||
scope :live, -> { published.limit(1) }
|
||||
scope :draft, -> { where(published_at: nil).order(id: :desc).limit(1) }
|
||||
|
||||
validates :text, presence: true
|
||||
validates :changelog, presence: true, if: -> { published? }
|
||||
|
||||
def published?
|
||||
published_at.present?
|
||||
end
|
||||
|
||||
def notification_sent?
|
||||
notification_sent_at.present?
|
||||
end
|
||||
|
||||
def scope_for_notification
|
||||
User.confirmed.joins(:account).merge(Account.without_suspended).where(created_at: (..published_at))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TermsOfService::Generator
|
||||
include ActiveModel::Model
|
||||
|
||||
TEMPLATE = Rails.root.join('config', 'templates', 'terms-of-service.md').read
|
||||
|
||||
VARIABLES = %i(
|
||||
admin_email
|
||||
arbitration_address
|
||||
arbitration_website
|
||||
dmca_address
|
||||
dmca_email
|
||||
domain
|
||||
jurisdiction
|
||||
).freeze
|
||||
|
||||
attr_accessor(*VARIABLES)
|
||||
|
||||
validates(*VARIABLES, presence: true)
|
||||
|
||||
def render
|
||||
format(TEMPLATE, VARIABLES.index_with { |key| public_send(key) })
|
||||
end
|
||||
end
|
||||
@@ -5,11 +5,11 @@
|
||||
# Table name: tombstones
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# by_moderator :boolean
|
||||
# uri :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# by_moderator :boolean
|
||||
# account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class Tombstone < ApplicationRecord
|
||||
|
||||
@@ -34,19 +34,7 @@ class Trends::Base
|
||||
end
|
||||
|
||||
def query
|
||||
Trends::Query.new(key_prefix, klass)
|
||||
end
|
||||
|
||||
def score(id, locale: nil)
|
||||
redis.zscore([key_prefix, 'all', locale].compact.join(':'), id) || 0
|
||||
end
|
||||
|
||||
def rank(id, locale: nil)
|
||||
redis.zrevrank([key_prefix, 'allowed', locale].compact.join(':'), id)
|
||||
end
|
||||
|
||||
def currently_trending_ids(allowed, limit)
|
||||
redis.zrevrange(allowed ? "#{key_prefix}:allowed" : "#{key_prefix}:all", 0, limit.positive? ? limit - 1 : limit).map(&:to_i)
|
||||
Trends::Query.new(klass)
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -64,42 +52,9 @@ class Trends::Base
|
||||
redis.expire(used_key(at_time), 1.day.seconds)
|
||||
end
|
||||
|
||||
def score_at_rank(rank)
|
||||
redis.zrevrange("#{key_prefix}:allowed", 0, rank, with_scores: true).last&.last || 0
|
||||
end
|
||||
|
||||
def replace_items(suffix, items)
|
||||
tmp_prefix = "#{key_prefix}:tmp:#{SecureRandom.alphanumeric(6)}#{suffix}"
|
||||
allowed_items = filter_for_allowed_items(items)
|
||||
|
||||
redis.pipelined do |pipeline|
|
||||
items.each { |item| pipeline.zadd("#{tmp_prefix}:all", item[:score], item[:item].id) }
|
||||
allowed_items.each { |item| pipeline.zadd("#{tmp_prefix}:allowed", item[:score], item[:item].id) }
|
||||
|
||||
rename_set(pipeline, "#{tmp_prefix}:all", "#{key_prefix}:all#{suffix}", items)
|
||||
rename_set(pipeline, "#{tmp_prefix}:allowed", "#{key_prefix}:allowed#{suffix}", allowed_items)
|
||||
end
|
||||
end
|
||||
|
||||
def filter_for_allowed_items(items)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def used_key(at_time)
|
||||
"#{key_prefix}:used:#{at_time.beginning_of_day.to_i}"
|
||||
end
|
||||
|
||||
def rename_set(pipeline, from_key, to_key, set_items)
|
||||
if set_items.empty?
|
||||
pipeline.del(to_key)
|
||||
else
|
||||
pipeline.rename(from_key, to_key)
|
||||
end
|
||||
end
|
||||
|
||||
def skip_review?
|
||||
Setting.trendable_by_default
|
||||
end
|
||||
end
|
||||
@@ -14,15 +14,6 @@ class Trends::Links < Trends::Base
|
||||
}
|
||||
|
||||
class Query < Trends::Query
|
||||
def filtered_for!(account)
|
||||
@account = account
|
||||
self
|
||||
end
|
||||
|
||||
def filtered_for(account)
|
||||
clone.filtered_for!(account)
|
||||
end
|
||||
|
||||
def to_arel
|
||||
scope = PreviewCard.joins(:trend).reorder(score: :desc)
|
||||
scope = scope.reorder(language_order_clause.desc, score: :desc) if preferred_languages.present?
|
||||
@@ -37,14 +28,6 @@ class Trends::Links < Trends::Base
|
||||
def language_order_clause
|
||||
Arel::Nodes::Case.new.when(PreviewCardTrend.arel_table[:language].in(preferred_languages)).then(1).else(0)
|
||||
end
|
||||
|
||||
def preferred_languages
|
||||
if @account&.chosen_languages.present?
|
||||
@account.chosen_languages
|
||||
else
|
||||
@locale
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def register(status, at_time = Time.now.utc)
|
||||
|
||||
+20
-37
@@ -1,19 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Trends::Query
|
||||
include Redisable
|
||||
include Enumerable
|
||||
|
||||
attr_reader :prefix, :klass, :loaded
|
||||
attr_reader :klass, :loaded
|
||||
|
||||
alias loaded? loaded
|
||||
|
||||
def initialize(prefix, klass)
|
||||
@prefix = prefix
|
||||
def initialize(_prefix, klass)
|
||||
@klass = klass
|
||||
@records = []
|
||||
@loaded = false
|
||||
@allowed = false
|
||||
@account = nil
|
||||
@limit = nil
|
||||
@offset = nil
|
||||
end
|
||||
@@ -27,6 +26,15 @@ class Trends::Query
|
||||
clone.allowed!
|
||||
end
|
||||
|
||||
def filtered_for!(account)
|
||||
@account = account
|
||||
self
|
||||
end
|
||||
|
||||
def filtered_for(account)
|
||||
clone.filtered_for!(account)
|
||||
end
|
||||
|
||||
def in_locale!(value)
|
||||
@locale = value
|
||||
self
|
||||
@@ -68,22 +76,11 @@ class Trends::Query
|
||||
alias to_a to_ary
|
||||
|
||||
def to_arel
|
||||
if ids_for_key.empty?
|
||||
klass.none
|
||||
else
|
||||
scope = klass.joins(sanitized_join_sql).reorder('x.ordering')
|
||||
scope = scope.offset(@offset) if @offset.present?
|
||||
scope = scope.limit(@limit) if @limit.present?
|
||||
scope
|
||||
end
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def key
|
||||
[@prefix, @allowed ? 'allowed' : 'all', @locale].compact.join(':')
|
||||
end
|
||||
|
||||
def load
|
||||
unless loaded?
|
||||
@records = perform_queries
|
||||
@@ -93,29 +90,15 @@ class Trends::Query
|
||||
self
|
||||
end
|
||||
|
||||
def ids_for_key
|
||||
@ids_for_key ||= redis.zrevrange(key, 0, -1).map(&:to_i)
|
||||
end
|
||||
|
||||
def sanitized_join_sql
|
||||
ActiveRecord::Base.sanitize_sql_array(join_sql_array)
|
||||
end
|
||||
|
||||
def join_sql_array
|
||||
[join_sql_query, ids_for_key]
|
||||
end
|
||||
|
||||
def join_sql_query
|
||||
<<~SQL.squish
|
||||
JOIN unnest(array[?]) WITH ordinality AS x (id, ordering) ON #{klass.table_name}.id = x.id
|
||||
SQL
|
||||
end
|
||||
|
||||
def perform_queries
|
||||
apply_scopes(to_arel).to_a
|
||||
to_arel.to_a
|
||||
end
|
||||
|
||||
def apply_scopes(scope)
|
||||
scope
|
||||
def preferred_languages
|
||||
if @account&.chosen_languages.present?
|
||||
@account.chosen_languages
|
||||
else
|
||||
@locale
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -13,15 +13,6 @@ class Trends::Statuses < Trends::Base
|
||||
}
|
||||
|
||||
class Query < Trends::Query
|
||||
def filtered_for!(account)
|
||||
@account = account
|
||||
self
|
||||
end
|
||||
|
||||
def filtered_for(account)
|
||||
clone.filtered_for!(account)
|
||||
end
|
||||
|
||||
def to_arel
|
||||
scope = Status.joins(:trend).reorder(score: :desc)
|
||||
scope = scope.reorder(language_order_clause.desc, score: :desc) if preferred_languages.present?
|
||||
@@ -37,14 +28,6 @@ class Trends::Statuses < Trends::Base
|
||||
def language_order_clause
|
||||
Arel::Nodes::Case.new.when(StatusTrend.arel_table[:language].in(preferred_languages)).then(1).else(0)
|
||||
end
|
||||
|
||||
def preferred_languages
|
||||
if @account&.chosen_languages.present?
|
||||
@account.chosen_languages
|
||||
else
|
||||
@locale
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def register(status, at_time = Time.now.utc)
|
||||
|
||||
@@ -6,6 +6,8 @@ class Trends::TagFilter
|
||||
status
|
||||
).freeze
|
||||
|
||||
IGNORED_PARAMS = %w(page).freeze
|
||||
|
||||
attr_reader :params
|
||||
|
||||
def initialize(params)
|
||||
@@ -13,14 +15,10 @@ class Trends::TagFilter
|
||||
end
|
||||
|
||||
def results
|
||||
scope = if params[:status] == 'pending_review'
|
||||
Tag.unscoped.order(id: :desc)
|
||||
else
|
||||
trending_scope
|
||||
end
|
||||
scope = initial_scope
|
||||
|
||||
params.each do |key, value|
|
||||
next if key.to_s == 'page'
|
||||
next if IGNORED_PARAMS.include?(key.to_s)
|
||||
|
||||
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
||||
end
|
||||
@@ -30,19 +28,24 @@ class Trends::TagFilter
|
||||
|
||||
private
|
||||
|
||||
def initial_scope
|
||||
Tag.select(Tag.arel_table[Arel.star])
|
||||
.joins(:trend)
|
||||
.eager_load(:trend)
|
||||
.reorder(score: :desc)
|
||||
end
|
||||
|
||||
def scope_for(key, value)
|
||||
case key.to_s
|
||||
when 'status'
|
||||
status_scope(value)
|
||||
when 'trending'
|
||||
trending_scope(value)
|
||||
else
|
||||
raise "Unknown filter: #{key}"
|
||||
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def trending_scope
|
||||
Trends.tags.query.to_arel
|
||||
end
|
||||
|
||||
def status_scope(value)
|
||||
case value.to_s
|
||||
when 'approved'
|
||||
@@ -52,7 +55,16 @@ class Trends::TagFilter
|
||||
when 'pending_review'
|
||||
Tag.pending_review
|
||||
else
|
||||
raise "Unknown status: #{value}"
|
||||
raise Mastodon::InvalidParameterError, "Unknown status: #{value}"
|
||||
end
|
||||
end
|
||||
|
||||
def trending_scope(value)
|
||||
case value
|
||||
when 'allowed'
|
||||
TagTrend.allowed
|
||||
else
|
||||
TagTrend.all
|
||||
end
|
||||
end
|
||||
end
|
||||
+51
-21
@@ -3,6 +3,8 @@
|
||||
class Trends::Tags < Trends::Base
|
||||
PREFIX = 'trending_tags'
|
||||
|
||||
BATCH_SIZE = 100
|
||||
|
||||
self.default_options = {
|
||||
threshold: 5,
|
||||
review_threshold: 3,
|
||||
@@ -11,6 +13,22 @@ class Trends::Tags < Trends::Base
|
||||
decay_threshold: 1,
|
||||
}
|
||||
|
||||
class Query < Trends::Query
|
||||
def to_arel
|
||||
scope = Tag.joins(:trend).reorder(language_order_clause.desc, score: :desc)
|
||||
scope = scope.merge(TagTrend.allowed) if @allowed
|
||||
scope = scope.offset(@offset) if @offset.present?
|
||||
scope = scope.limit(@limit) if @limit.present?
|
||||
scope
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def language_order_clause
|
||||
Arel::Nodes::Case.new.when(TagTrend.arel_table[:language].in(preferred_languages)).then(1).else(0)
|
||||
end
|
||||
end
|
||||
|
||||
def register(status, at_time = Time.now.utc)
|
||||
return unless !status.reblog? && status.public_visibility? && !status.account.silenced?
|
||||
|
||||
@@ -24,19 +42,39 @@ class Trends::Tags < Trends::Base
|
||||
record_used_id(tag.id, at_time)
|
||||
end
|
||||
|
||||
def query
|
||||
Query.new(key_prefix, klass)
|
||||
end
|
||||
|
||||
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)
|
||||
# First, recalculate scores for tags that were trending previously. We split the queries
|
||||
# to avoid having to load all of the IDs into Ruby just to send them back into Postgres
|
||||
Tag.where(id: TagTrend.select(:tag_id)).find_in_batches(batch_size: BATCH_SIZE) do |tags|
|
||||
calculate_scores(tags, at_time)
|
||||
end
|
||||
|
||||
# Then, calculate scores for tags that were used today. There are potentially some
|
||||
# duplicate items here that we might process one more time, but that should be fine
|
||||
Tag.where(id: recently_used_ids(at_time)).find_in_batches(batch_size: BATCH_SIZE) do |tags|
|
||||
calculate_scores(tags, at_time)
|
||||
end
|
||||
|
||||
# Now that all trends have up-to-date scores, and all the ones below the threshold have
|
||||
# been removed, we can recalculate their positions
|
||||
TagTrend.recalculate_ordered_rank
|
||||
end
|
||||
|
||||
def request_review
|
||||
tags = Tag.where(id: currently_trending_ids(false, -1))
|
||||
score_at_threshold = TagTrend.allowed.by_rank.ranked_below(options[:review_threshold]).first&.score || 0
|
||||
tag_trends = TagTrend.not_allowed.includes(:tag)
|
||||
|
||||
tags.filter_map do |tag|
|
||||
next unless would_be_trending?(tag.id) && !tag.trendable? && tag.requires_review_notification?
|
||||
tag_trends.filter_map do |trend|
|
||||
tag = trend.tag
|
||||
|
||||
tag.touch(:requested_review_at)
|
||||
tag
|
||||
if trend.score > score_at_threshold && !tag.trendable? && tag.requires_review_notification?
|
||||
tag.touch(:requested_review_at)
|
||||
tag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,9 +91,7 @@ class Trends::Tags < Trends::Base
|
||||
private
|
||||
|
||||
def calculate_scores(tags, at_time)
|
||||
items = []
|
||||
|
||||
tags.each do |tag|
|
||||
items = tags.map do |tag|
|
||||
expected = tag.history.get(at_time - 1.day).accounts.to_f
|
||||
expected = 1.0 if expected.zero?
|
||||
observed = tag.history.get(at_time).accounts.to_f
|
||||
@@ -79,19 +115,13 @@ 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))
|
||||
|
||||
next unless decaying_score >= options[:decay_threshold]
|
||||
|
||||
items << { score: decaying_score, item: tag }
|
||||
[decaying_score, tag]
|
||||
end
|
||||
|
||||
replace_items('', items)
|
||||
end
|
||||
to_insert = items.filter { |(score, _)| score >= options[:decay_threshold] }
|
||||
to_delete = items.filter { |(score, _)| score < options[:decay_threshold] }
|
||||
|
||||
def filter_for_allowed_items(items)
|
||||
items.select { |item| item[:item].trendable? }
|
||||
end
|
||||
|
||||
def would_be_trending?(id)
|
||||
score(id) > score_at_rank(options[:review_threshold] - 1)
|
||||
TagTrend.upsert_all(to_insert.map { |(score, tag)| { tag_id: tag.id, score: score, language: '', allowed: tag.trendable? || false } }, unique_by: %w(tag_id language)) if to_insert.any?
|
||||
TagTrend.where(tag_id: to_delete.map { |(_, tag)| tag.id }).delete_all if to_delete.any?
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -350,7 +350,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def revoke_access!
|
||||
Doorkeeper::AccessGrant.by_resource_owner(self).update_all(revoked_at: Time.now.utc)
|
||||
Doorkeeper::AccessGrant.by_resource_owner(self).touch_all(:revoked_at)
|
||||
|
||||
Doorkeeper::AccessToken.by_resource_owner(self).in_batches do |batch|
|
||||
batch.touch_all(:revoked_at)
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
# Table name: user_invite_requests
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# user_id :bigint(8)
|
||||
# text :text
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class UserInviteRequest < ApplicationRecord
|
||||
|
||||
@@ -41,6 +41,8 @@ class UserRole < ApplicationRecord
|
||||
EVERYONE_ROLE_ID = -99
|
||||
NOBODY_POSITION = -1
|
||||
|
||||
POSITION_LIMIT = (2**31) - 1
|
||||
|
||||
module Flags
|
||||
NONE = 0
|
||||
ALL = FLAGS.values.reduce(&:|)
|
||||
@@ -89,6 +91,7 @@ class UserRole < ApplicationRecord
|
||||
|
||||
validates :name, presence: true, unless: :everyone?
|
||||
validates :color, format: { with: /\A#?(?:[A-F0-9]{3}){1,2}\z/i }, unless: -> { color.blank? }
|
||||
validates :position, numericality: { in: (-POSITION_LIMIT..POSITION_LIMIT) }
|
||||
|
||||
validate :validate_permissions_elevation
|
||||
validate :validate_position_elevation
|
||||
|
||||
@@ -28,6 +28,7 @@ class UserSettings
|
||||
setting :use_blurhash, default: true
|
||||
setting :use_pending_items, default: false
|
||||
setting :use_system_font, default: false
|
||||
setting :use_system_scrollbars, default: false
|
||||
setting :disable_swiping, default: false
|
||||
setting :disable_hover_cards, default: false
|
||||
setting :delete_modal, default: true
|
||||
|
||||
Reference in new issue
Block a user