From 7fae5ca3b81243941f54e1be585e05c283076da4 Mon Sep 17 00:00:00 2001 From: Thorsten Claus Date: Thu, 15 Apr 2021 08:14:54 +0200 Subject: [PATCH] More optimized and faster query for local public posts Even faster with new index --- app/models/post.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 1905854fa..211972931 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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) {