mirror of https://github.com/mastodon/mastodon
Extract method for self-referencing records in `AccountStatusCleanupPolicy` (#31244)
This commit is contained in:
parent
1c17dca6d9
commit
58df00f04d
|
@ -145,15 +145,15 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_self_fav_scope
|
def without_self_fav_scope
|
||||||
Status.where('NOT EXISTS (SELECT 1 FROM favourites fav WHERE fav.account_id = statuses.account_id AND fav.status_id = statuses.id)')
|
Status.where.not(self_status_reference_exists(Favourite))
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_self_bookmark_scope
|
def without_self_bookmark_scope
|
||||||
Status.where('NOT EXISTS (SELECT 1 FROM bookmarks bookmark WHERE bookmark.account_id = statuses.account_id AND bookmark.status_id = statuses.id)')
|
Status.where.not(self_status_reference_exists(Bookmark))
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_pinned_scope
|
def without_pinned_scope
|
||||||
Status.where('NOT EXISTS (SELECT 1 FROM status_pins pin WHERE pin.account_id = statuses.account_id AND pin.status_id = statuses.id)')
|
Status.where.not(self_status_reference_exists(StatusPin))
|
||||||
end
|
end
|
||||||
|
|
||||||
def without_media_scope
|
def without_media_scope
|
||||||
|
@ -174,4 +174,13 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
|
||||||
def account_statuses
|
def account_statuses
|
||||||
Status.where(account_id: account_id)
|
Status.where(account_id: account_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self_status_reference_exists(model)
|
||||||
|
model
|
||||||
|
.where(model.arel_table[:account_id].eq Status.arel_table[:account_id])
|
||||||
|
.where(model.arel_table[:status_id].eq Status.arel_table[:id])
|
||||||
|
.select(1)
|
||||||
|
.arel
|
||||||
|
.exists
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue