[home] Refactor the home timeline query
This commit is contained in:
parent
3f6e8a62fd
commit
4adbadddaa
|
@ -19,31 +19,24 @@ class HomeFeed < Feed
|
||||||
pagination_max = "and s.id < #{max_id}" unless max_id.nil?
|
pagination_max = "and s.id < #{max_id}" unless max_id.nil?
|
||||||
pagination_min = "and s.id > #{min_id}" unless min_id.nil?
|
pagination_min = "and s.id > #{min_id}" unless min_id.nil?
|
||||||
Status.find_by_sql "
|
Status.find_by_sql "
|
||||||
select st.* from (
|
select s.*
|
||||||
select s.*
|
|
||||||
from statuses s
|
from statuses s
|
||||||
left join statuses reblog
|
left join statuses r
|
||||||
on s.reblog_of_id = reblog.id
|
on s.reblog_of_id = r.id
|
||||||
where
|
where
|
||||||
s.created_at > NOW() - INTERVAL '7 days'
|
s.created_at > NOW() - INTERVAL '7 days'
|
||||||
and s.reply is false
|
and s.reply is false
|
||||||
and (
|
and (
|
||||||
s.account_id = #{@id}
|
exists(select ff.target_account_id from follows ff
|
||||||
or s.account_id in (
|
where ff.account_id = #{@id} and ff.target_account_id = s.account_id)
|
||||||
select ff.target_account_id
|
or s.account_id = #{@id})
|
||||||
from follows ff
|
and not exists(select mm.target_account_id from mutes mm
|
||||||
join accounts af
|
where mm.account_id = #{@id} and mm.target_account_id in (s.account_id, r.account_id))
|
||||||
on ff.target_account_id = af.id
|
and not exists(select bb.target_account_id from blocks bb
|
||||||
where ff.account_id = #{@id})
|
where bb.account_id = #{@id} and bb.target_account_id in (s.account_id, r.account_id))
|
||||||
)
|
#{pagination_max}
|
||||||
and s.account_id not in (select target_account_id from mutes where account_id = #{@id})
|
#{pagination_min}
|
||||||
and (reblog.id is null or reblog.account_id not in (select target_account_id from mutes where account_id = #{@id}))
|
order by s.created_at desc limit #{limit}
|
||||||
and (reblog.id is null or reblog.account_id not in (select target_account_id from blocks where account_id = #{@id}))
|
|
||||||
#{pagination_max}
|
|
||||||
#{pagination_min}
|
|
||||||
order by s.created_at desc
|
|
||||||
limit #{limit}
|
|
||||||
) st
|
|
||||||
"
|
"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue