mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:16:41 +08:00
PERF: improve performance for featured user calculation
This commit is contained in:
parent
6037a6b0c9
commit
40b22bf367
|
@ -24,6 +24,8 @@ class TopicFeaturedUsers
|
|||
|
||||
def self.ensure_consistency!(topic_id=nil)
|
||||
|
||||
filter = "#{"AND t.id = #{topic_id.to_i}" if topic_id}"
|
||||
|
||||
sql = <<SQL
|
||||
|
||||
WITH cte as (
|
||||
|
@ -38,6 +40,7 @@ WITH cte as (
|
|||
NOT p.hidden AND
|
||||
p.user_id <> t.user_id AND
|
||||
p.user_id <> t.last_post_user_id
|
||||
#{filter}
|
||||
GROUP BY t.id, p.user_id
|
||||
),
|
||||
|
||||
|
@ -69,7 +72,7 @@ WHERE x.id = tt.id AND
|
|||
COALESCE(featured_user2_id,-99) <> COALESCE(featured_user2,-99) OR
|
||||
COALESCE(featured_user3_id,-99) <> COALESCE(featured_user3,-99) OR
|
||||
COALESCE(featured_user4_id,-99) <> COALESCE(featured_user4,-99)
|
||||
) #{"AND x.id = #{topic_id.to_i}" if topic_id}
|
||||
)
|
||||
SQL
|
||||
|
||||
Topic.exec_sql(sql)
|
||||
|
|
Loading…
Reference in New Issue
Block a user