mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
PERF: Optimize the performance of TopicLink.topic_map
query (#19630)
Instead of relying on the `ILIKE` operator to filter out image links, we can instead rely on the `TopicLink#extension` column which allows us to more efficiently filter out image links. This optimization mainly affects topics that are link heavy which is common in topics with alot of replies. When profiling a production instance for a topic with 10K replies and 2.5K `topic_links`, this optimization reduces the query time from ~18ms to around ~4ms.
This commit is contained in:
parent
aad63d92d2
commit
070eac16a8
@ -58,8 +58,7 @@ class TopicLink < ActiveRecord::Base
|
|||||||
|
|
||||||
builder.where('ftl.topic_id = :topic_id', topic_id: topic_id)
|
builder.where('ftl.topic_id = :topic_id', topic_id: topic_id)
|
||||||
builder.where('ft.deleted_at IS NULL')
|
builder.where('ft.deleted_at IS NULL')
|
||||||
# note that ILIKE means "case insensitive LIKE"
|
builder.where("ftl.extension IS NULL OR ftl.extension NOT IN ('png','jpg','gif')")
|
||||||
builder.where("NOT(ftl.url ILIKE '%.png' OR ftl.url ILIKE '%.jpg' OR ftl.url ILIKE '%.gif')")
|
|
||||||
builder.where("COALESCE(ft.archetype, 'regular') <> :archetype", archetype: Archetype.private_message)
|
builder.where("COALESCE(ft.archetype, 'regular') <> :archetype", archetype: Archetype.private_message)
|
||||||
builder.where("clicks > 0")
|
builder.where("clicks > 0")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user