From 46b1e91aa6d79218a0af23ddef9907c0d954cfc3 Mon Sep 17 00:00:00 2001 From: Jens Kraemer Date: Thu, 28 Apr 2022 19:31:35 +0800 Subject: [PATCH] Attachment activity provider sql optimization the OR in the second JOIN makes things really slow for large numbers of attachments (at least on MySQL). The redundant where clause speeds things up by limiting the number of attachments rows early on. This will not help if most attachments belong to versions or projects, but that is rarely the case. --- app/models/attachment.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index bbc9a4660d..7c60c71644 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -48,6 +48,7 @@ class Attachment < ActiveRecord::Base :scope => proc do select("#{Attachment.table_name}.*"). + where(container_type: ['Version', 'Project']). joins( "LEFT JOIN #{Version.table_name} " \ "ON #{Attachment.table_name}.container_type='Version' " \ -- 2.20.1