diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-05-26 18:34:27 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-05-26 18:34:27 +0200 |
commit | f13d910f3ea3af1e6b5ff2ebfa084a86b1d7dfde (patch) | |
tree | 6e373aa9ced74f68ee366cc50e23d14a524c36f9 /app/models | |
parent | 444b65009411a08ddab95ec60b86b3cf63086c2e (diff) | |
parent | 088dc0ec5a383006952c0b15508af882a4c1109c (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 9 | ||||
-rw-r--r-- | app/models/poll.rb | 5 | ||||
-rw-r--r-- | app/models/status.rb | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index f4fc32153..7c81e07d9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -113,7 +113,8 @@ class Account < ApplicationRecord scope :matches_username, ->(value) { where(arel_table[:username].matches("#{value}%")) } scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) } scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) } - scope :searchable, -> { without_suspended.where(moved_to_account_id: nil) } + scope :without_unapproved, -> { left_outer_joins(:user).remote.or(left_outer_joins(:user).merge(User.approved.confirmed)) } + scope :searchable, -> { without_unapproved.without_suspended.where(moved_to_account_id: nil) } scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).left_outer_joins(:account_stat) } scope :followable_by, ->(account) { joins(arel_table.join(Follow.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:id].eq(Follow.arel_table[:target_account_id]).and(Follow.arel_table[:account_id].eq(account.id))).join_sources).where(Follow.arel_table[:id].eq(nil)).joins(arel_table.join(FollowRequest.arel_table, Arel::Nodes::OuterJoin).on(arel_table[:id].eq(FollowRequest.arel_table[:target_account_id]).and(FollowRequest.arel_table[:account_id].eq(account.id))).join_sources).where(FollowRequest.arel_table[:id].eq(nil)) } scope :by_recent_status, -> { order(Arel.sql('(case when account_stats.last_status_at is null then 1 else 0 end) asc, account_stats.last_status_at desc, accounts.id desc')) } @@ -197,7 +198,7 @@ class Account < ApplicationRecord end def searchable? - !(suspended? || moved?) + !(suspended? || moved?) && (!local? || (approved? && confirmed?)) end def possibly_stale? @@ -463,9 +464,11 @@ class Account < ApplicationRecord accounts.*, ts_rank_cd(#{TEXTSEARCH}, to_tsquery('simple', :tsquery), 32) AS rank FROM accounts + LEFT JOIN users ON accounts.id = users.account_id WHERE to_tsquery('simple', :tsquery) @@ #{TEXTSEARCH} AND accounts.suspended_at IS NULL AND accounts.moved_to_account_id IS NULL + AND (accounts.domain IS NOT NULL OR (users.approved = TRUE AND users.confirmed_at IS NOT NULL)) ORDER BY rank DESC LIMIT :limit OFFSET :offset SQL @@ -541,9 +544,11 @@ class Account < ApplicationRecord (count(f.id) + 1) * ts_rank_cd(#{TEXTSEARCH}, to_tsquery('simple', :tsquery), 32) AS rank FROM accounts LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = :id) OR (accounts.id = f.target_account_id AND f.account_id = :id) + LEFT JOIN users ON accounts.id = users.account_id WHERE to_tsquery('simple', :tsquery) @@ #{TEXTSEARCH} AND accounts.suspended_at IS NULL AND accounts.moved_to_account_id IS NULL + AND (accounts.domain IS NOT NULL OR (users.approved = TRUE AND users.confirmed_at IS NOT NULL)) GROUP BY accounts.id ORDER BY rank DESC LIMIT :limit OFFSET :offset diff --git a/app/models/poll.rb b/app/models/poll.rb index ba08309a1..1a326e452 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -39,13 +39,12 @@ class Poll < ApplicationRecord before_validation :prepare_options, if: :local? before_validation :prepare_votes_count - - after_initialize :prepare_cached_tallies + before_validation :prepare_cached_tallies after_commit :reset_parent_cache, on: :update def loaded_options - options.map.with_index { |title, key| Option.new(self, key.to_s, title, show_totals_now? ? cached_tallies[key] : nil) } + options.map.with_index { |title, key| Option.new(self, key.to_s, title, show_totals_now? ? (cached_tallies[key] || 0) : nil) } end def possibly_stale? diff --git a/app/models/status.rb b/app/models/status.rb index 21a574a71..3efa23ae2 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -511,7 +511,7 @@ class Status < ApplicationRecord end def set_poll_id - update_column(:poll_id, poll.id) unless poll.nil? + update_column(:poll_id, poll.id) if association(:poll).loaded? && poll.present? end def set_visibility |