Use a constant

This commit is contained in:
rubic0n 2021-02-28 19:50:01 -06:00
parent 6e42e3b1ec
commit 3b704cec7d
1 changed files with 36 additions and 39 deletions

View File

@ -1,22 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class HomeFeed < Feed class HomeFeed < Feed
def initialize(account) QUERY = <<-SQL
@type = :home
@id = account.id
@account = account
end
def get(limit = 20, max_id = nil, since_id = nil, min_id = nil)
ActiveRecord::Base.connected_to(role: :reading) do
from_database(limit, max_id, since_id, min_id)
end
end
private
def from_database(limit, max_id, since_id, min_id)
Status.find_by_sql([<<-SQL, { id: @id, limit: limit, min_id: min_id, max_id: max_id }])
with cte as with cte as
( (
select select
@ -50,5 +35,17 @@ class HomeFeed < Feed
cte.rn_dupe = 1 or cte.reblog_of_id is null cte.rn_dupe = 1 or cte.reblog_of_id is null
order by so.created_at desc order by so.created_at desc
SQL SQL
def initialize(account)
@type = :home
@id = account.id
@account = account
end
def get(limit = 20, max_id = nil, since_id = nil, min_id = nil)
ActiveRecord::Base.connected_to(role: :reading) do
Status.find_by_sql([QUERY, { id: @id, limit: limit, min_id: min_id, max_id: max_id }])
end end
end end
end