mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 02:48:28 +08:00
PERF: remove avg_time calculations and regular jobs from posts and topics
After careful analysis of large data-sets it became apparent that avg_time had no impact whatsoever on "best of" topic scoring. Calculating avg_time was a very costly operation especially on large databases. We have some longer term plans of introducing other weighting that is read time based into our scoring for "best of" and "top" topics, but in the interim to stop a large amount of work that is not achieving any value we are removing the jobs. Column removal will follow once we decide on a new replacement metric.
This commit is contained in:
@ -674,37 +674,6 @@ class Post < ActiveRecord::Base
|
||||
|
||||
end
|
||||
|
||||
# This calculates the geometric mean of the post timings and stores it along with
|
||||
# each post.
|
||||
def self.calculate_avg_time(min_topic_age = nil)
|
||||
retry_lock_error do
|
||||
builder = DB.build("UPDATE posts
|
||||
SET avg_time = (x.gmean / 1000)
|
||||
FROM (SELECT post_timings.topic_id,
|
||||
post_timings.post_number,
|
||||
round(exp(avg(CASE WHEN msecs > 0 THEN ln(msecs) ELSE 0 END))) AS gmean
|
||||
FROM post_timings
|
||||
INNER JOIN posts AS p2
|
||||
ON p2.post_number = post_timings.post_number
|
||||
AND p2.topic_id = post_timings.topic_id
|
||||
AND p2.user_id <> post_timings.user_id
|
||||
/*where2*/
|
||||
GROUP BY post_timings.topic_id, post_timings.post_number) AS x
|
||||
/*where*/")
|
||||
|
||||
builder.where("x.topic_id = posts.topic_id
|
||||
AND x.post_number = posts.post_number
|
||||
AND (posts.avg_time <> (x.gmean / 1000)::int OR posts.avg_time IS NULL)")
|
||||
|
||||
if min_topic_age
|
||||
builder.where2("p2.topic_id IN (SELECT id FROM topics where bumped_at > :bumped_at)",
|
||||
bumped_at: min_topic_age)
|
||||
end
|
||||
|
||||
builder.exec
|
||||
end
|
||||
end
|
||||
|
||||
before_save do
|
||||
self.last_editor_id ||= user_id
|
||||
|
||||
|
Reference in New Issue
Block a user