mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
PERF: improve perf on consistency query in importers
This commit is contained in:
parent
9d9d93ad3c
commit
78bcea5247
1 changed files with 17 additions and 2 deletions
|
@ -468,8 +468,23 @@ class ImportScripts::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_last_posted_at
|
def update_last_posted_at
|
||||||
puts "", "updaing last posted at on users"
|
puts "", "updating last posted at on users"
|
||||||
User.exec_sql("UPDATE users SET last_posted_at = (SELECT MAX(posts.created_at) FROM posts WHERE posts.user_id = users.id)")
|
|
||||||
|
sql = <<-SQL
|
||||||
|
WITH lpa AS (
|
||||||
|
SELECT user_id, MAX(posts.created_at) AS last_posted_at
|
||||||
|
FROM posts
|
||||||
|
GROUP BY user_id
|
||||||
|
)
|
||||||
|
UPDATE users
|
||||||
|
SET last_posted_at = lpa.last_posted_at
|
||||||
|
FROM users u1
|
||||||
|
JOIN lpa ON lpa.user_id = u1.id
|
||||||
|
WHERE u1.id = users.id
|
||||||
|
AND users.last_posted_at <> lpa.last_posted_at
|
||||||
|
SQL
|
||||||
|
|
||||||
|
User.exec_sql(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_feature_topic_users
|
def update_feature_topic_users
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue