PERF: Only refresh the Daily stats hourly, do the others daily.

This commit is contained in:
Robin Ward 2015-04-20 12:06:52 -04:00
parent 3071650eb3
commit 6ae58d41a7
4 changed files with 59 additions and 49 deletions

View File

@ -1,9 +0,0 @@
module Jobs
class DirectoryRefresh < Jobs::Scheduled
every 1.hour
def execute(args)
DirectoryItem.refresh!
end
end
end

View File

@ -0,0 +1,9 @@
module Jobs
class DirectoryRefreshDaily < Jobs::Scheduled
every 1.hour
def execute(args)
DirectoryItem.refresh_period!(:daily)
end
end
end

View File

@ -0,0 +1,10 @@
module Jobs
class DirectoryRefreshOlder < Jobs::Scheduled
every 1.day
def execute(args)
periods = DirectoryItem.period_types.keys - [:daily]
periods.each {|p| DirectoryItem.refresh_period!(p)}
end
end
end

View File

@ -17,11 +17,8 @@ class DirectoryItem < ActiveRecord::Base
end
def self.refresh!
ActiveRecord::Base.transaction do
exec_sql "TRUNCATE TABLE directory_items"
period_types.each_key {|p| refresh_period!(p)}
end
end
def self.refresh_period!(period_type)
@ -36,6 +33,8 @@ class DirectoryItem < ActiveRecord::Base
else 1000.years.ago
end
ActiveRecord::Base.transaction do
exec_sql "DELETE FROM directory_items WHERE period_type = :period_type", period_type: period_types[period_type]
exec_sql "INSERT INTO directory_items
(period_type, user_id, likes_received, likes_given, topics_entered, days_visited, posts_read, topic_count, post_count)
SELECT
@ -74,3 +73,4 @@ class DirectoryItem < ActiveRecord::Base
moderator_action: Post.types[:moderator_action]
end
end
end