From 355b6d5f84788ba831024d0160c76ee143d98fcc Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Thu, 12 Mar 2020 14:45:10 +0100 Subject: [PATCH] Performance: selector2sql for operator "contains one" of tags generates heavy CPU load on database server. --- app/models/ticket.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 05dae0886..0e165e21a 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -723,20 +723,14 @@ condition example bind_params.push selector['value'].count bind_params.push selector['value'] elsif selector['operator'] == 'contains one' && attributes[0] == 'ticket' && attributes[1] == 'tags' - query += "1 <= ( - SELECT - COUNT(*) - FROM - tag_objects, - tag_items, - tags - WHERE - tickets.id = tags.o_id AND - tag_objects.id = tags.tag_object_id AND - tag_objects.name = 'Ticket' AND - tag_items.id = tags.tag_item_id AND - tag_items.name IN (?) - )" + tables += ', tag_objects, tag_items, tags' + query += " + tickets.id = tags.o_id AND + tag_objects.id = tags.tag_object_id AND + tag_objects.name = 'Ticket' AND + tag_items.id = tags.tag_item_id AND + tag_items.name IN (?)" + bind_params.push selector['value'] elsif selector['operator'] == 'contains all not' && attributes[0] == 'ticket' && attributes[1] == 'tags' query += "0 = (