A platform for community discussion. Free, open, simple.
PERF: Optimize the performance of `TopicLink.topic_map` query (#19630)
Alan Guo Xiang Tan070eac16a85e
diff --git a/app/models/topic_link.rb b/app/models/topic_link.rbindex 977de9c2ac8..690779cb06e 100644--- a/app/models/topic_link.rb+++ b/app/models/topic_link.rb@@ -58,8 +58,7 @@ class TopicLink < ActiveRecord::Basebuilder.where('ftl.topic_id = :topic_id', topic_id: topic_id)builder.where('ft.deleted_at IS NULL')- # note that ILIKE means "case insensitive LIKE"- builder.where("NOT(ftl.url ILIKE '%.png' OR ftl.url ILIKE '%.jpg' OR ftl.url ILIKE '%.gif')")+ builder.where("ftl.extension IS NULL OR ftl.extension NOT IN ('png','jpg','gif')")builder.where("COALESCE(ft.archetype, 'regular') <> :archetype", archetype: Archetype.private_message)builder.where("clicks > 0")