More optimized and faster query for local public posts

Even faster with new index
This commit is contained in:
Thorsten Claus 2021-04-15 08:14:54 +02:00
parent 2db1d5d641
commit 7fae5ca3b8

View file

@ -52,9 +52,10 @@ class Post < ApplicationRecord
scope :all_public, -> { where(public: true) }
scope :all_local_public, -> {
left_outer_joins(author: [:pod])
.where("pods.host is null") # local posts have no host in pods
.where(public: true)
where(" exists (
select 1 from people where posts.author_id = people.id
and people.pod_id is null)
and posts.public = true")
}
scope :commented_by, ->(person) {