[home feed] Changes to reduce database use.
This commit is contained in:
parent
88fc6cb48a
commit
8413ca93a4
|
@ -88,28 +88,28 @@ class FeedManager
|
||||||
|
|
||||||
def filter_from_home?(status, receiver_id)
|
def filter_from_home?(status, receiver_id)
|
||||||
return false if receiver_id == status.account_id
|
return false if receiver_id == status.account_id
|
||||||
return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
|
# return true if status.reply? && (status.in_reply_to_id.nil? || status.in_reply_to_account_id.nil?)
|
||||||
return true if phrase_filtered?(status, receiver_id, :home)
|
return true if phrase_filtered?(status, receiver_id, :home)
|
||||||
|
|
||||||
check_for_blocks = status.active_mentions.pluck(:account_id)
|
# check_for_blocks = status.active_mentions.pluck(:account_id)
|
||||||
check_for_blocks.concat([status.account_id])
|
# check_for_blocks.concat([status.account_id])
|
||||||
|
|
||||||
if status.reblog?
|
# if status.reblog?
|
||||||
check_for_blocks.concat([status.reblog.account_id])
|
# check_for_blocks.concat([status.reblog.account_id])
|
||||||
check_for_blocks.concat(status.reblog.active_mentions.pluck(:account_id))
|
# check_for_blocks.concat(status.reblog.active_mentions.pluck(:account_id))
|
||||||
end
|
# end
|
||||||
|
|
||||||
return true if blocks_or_mutes?(receiver_id, check_for_blocks, :home)
|
# return true if blocks_or_mutes?(receiver_id, check_for_blocks, :home)
|
||||||
|
|
||||||
if status.reply? && !status.in_reply_to_account_id.nil? # Filter out if it's a reply
|
# if status.reply? && !status.in_reply_to_account_id.nil? # Filter out if it's a reply
|
||||||
should_filter = !Follow.where(account_id: receiver_id, target_account_id: status.in_reply_to_account_id).exists? # and I'm not following the person it's a reply to
|
# should_filter = !Follow.where(account_id: receiver_id, target_account_id: status.in_reply_to_account_id).exists? # and I'm not following the person it's a reply to
|
||||||
should_filter &&= receiver_id != status.in_reply_to_account_id # and it's not a reply to me
|
# should_filter &&= receiver_id != status.in_reply_to_account_id # and it's not a reply to me
|
||||||
should_filter &&= status.account_id != status.in_reply_to_account_id # and it's not a self-reply
|
# should_filter &&= status.account_id != status.in_reply_to_account_id # and it's not a self-reply
|
||||||
return should_filter
|
# return should_filter
|
||||||
elsif status.reblog? # Filter out a reblog
|
#elsif status.reblog? # Filter out a reblog
|
||||||
should_filter ||= Block.where(account_id: status.reblog.account_id, target_account_id: receiver_id).exists? # or if the author of the reblogged status is blocking me
|
# should_filter ||= Block.where(account_id: status.reblog.account_id, target_account_id: receiver_id).exists? # or if the author of the reblogged status is blocking me
|
||||||
return should_filter
|
# return should_filter
|
||||||
end
|
#end
|
||||||
|
|
||||||
return false if status.group_id
|
return false if status.group_id
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ class HomeFeed < Feed
|
||||||
def from_database(limit, max_id, since_id, min_id)
|
def from_database(limit, max_id, since_id, min_id)
|
||||||
Status.as_home_timeline(@account)
|
Status.as_home_timeline(@account)
|
||||||
.paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
.paginate_by_id(limit, max_id: max_id, since_id: since_id, min_id: min_id)
|
||||||
|
.excluding_blocked_reblogs(@account)
|
||||||
|
.not_excluded_by_account(@account)
|
||||||
.reject { |status| FeedManager.instance.filter?(:home, status, @account.id) }
|
.reject { |status| FeedManager.instance.filter?(:home, status, @account.id) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -101,6 +101,9 @@ class Status < ApplicationRecord
|
||||||
scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }
|
scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }
|
||||||
scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
|
scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
|
||||||
scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) }
|
scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) }
|
||||||
|
|
||||||
|
scope :excluding_blocked_reblogs, ->(account) { left_outer_joins(:reblog).where.not(accounts: account.excluded_from_timeline_account_ids) }
|
||||||
|
|
||||||
scope :popular_accounts, -> { left_outer_joins(:account).where('accounts.is_verified=true OR accounts.is_pro=true AND accounts.locked=false') }
|
scope :popular_accounts, -> { left_outer_joins(:account).where('accounts.is_verified=true OR accounts.is_pro=true AND accounts.locked=false') }
|
||||||
scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) }
|
scope :not_excluded_by_account, ->(account) { where.not(account_id: account.excluded_from_timeline_account_ids) }
|
||||||
scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) }
|
scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) }
|
||||||
|
@ -290,7 +293,7 @@ class Status < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_home_timeline(account)
|
def as_home_timeline(account)
|
||||||
query = where('created_at > ?', 3.days.ago)
|
query = where('statuses.created_at > ?', 3.days.ago)
|
||||||
query.where(account: [account] + account.following).without_replies
|
query.where(account: [account] + account.following).without_replies
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue