From 183cb40e74e610899cf7f7870ac44be4d8487bba Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Tue, 27 Feb 2024 14:07:20 -0800 Subject: [PATCH] Oops, don't return body_id=0 items for "-fits:blue-acara" Right, fitting isn't just body_id = this one, it's also body_id=0! Anyway, doing this query on its own is still deathly slow, I wonder if the idea I had about left joins (back when I was still working in a Rails version that didn't support it lol) could help! Might poke at that a smidge. --- app/models/item.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/item.rb b/app/models/item.rb index 68006449..c0f4bf7a 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -103,7 +103,11 @@ class Item < ApplicationRecord # bother looking into this, but one thing I notice is items with no assets # somehow would not match either scope in this impl (but LEFT JOIN would!) joins(:swf_assets).group(i[:id]). - having('FIND_IN_SET(?, GROUP_CONCAT(body_id)) = 0', body_id). + having( + "FIND_IN_SET(?, GROUP_CONCAT(body_id)) = 0 AND " + + "FIND_IN_SET(0, GROUP_CONCAT(body_id)) = 0", + body_id + ). distinct }