mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 08:23:43 +08:00
FIX database growth when running the PeriodicalUpdates job
This commit is contained in:
parent
75a8dfc467
commit
01075c5e7a
|
@ -22,7 +22,6 @@ class ScoreCalculator
|
||||||
exec_sql(post_score_sql, @weightings)
|
exec_sql(post_score_sql, @weightings)
|
||||||
|
|
||||||
# Update the percent rankings of the posts
|
# Update the percent rankings of the posts
|
||||||
|
|
||||||
exec_sql("UPDATE posts SET percent_rank = x.percent_rank
|
exec_sql("UPDATE posts SET percent_rank = x.percent_rank
|
||||||
FROM (SELECT id, percent_rank()
|
FROM (SELECT id, percent_rank()
|
||||||
OVER (PARTITION BY topic_id ORDER BY SCORE DESC) as percent_rank
|
OVER (PARTITION BY topic_id ORDER BY SCORE DESC) as percent_rank
|
||||||
|
@ -73,12 +72,12 @@ class ScoreCalculator
|
||||||
|
|
||||||
# Generate a SQL statement to update the scores of all posts
|
# Generate a SQL statement to update the scores of all posts
|
||||||
def post_score_sql
|
def post_score_sql
|
||||||
"UPDATE posts SET score = ".tap do |sql|
|
components = []
|
||||||
components = []
|
@weightings.keys.each { |k| components << "COALESCE(#{k.to_s}, 0) * :#{k.to_s}" }
|
||||||
@weightings.keys.each do |k|
|
components = components.join(" + ")
|
||||||
components << "COALESCE(#{k.to_s}, 0) * :#{k.to_s}"
|
|
||||||
end
|
"UPDATE posts SET score = x.score
|
||||||
sql << components.join(" + ")
|
FROM (SELECT id, #{components} as score FROM posts) AS x
|
||||||
end
|
WHERE x.id = posts.id AND (posts.score IS NULL OR x.score <> posts.score)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user