PERF: Only refresh the Daily stats hourly, do the others daily.
This commit is contained in:
parent
3071650eb3
commit
6ae58d41a7
|
@ -1,9 +0,0 @@
|
||||||
module Jobs
|
|
||||||
class DirectoryRefresh < Jobs::Scheduled
|
|
||||||
every 1.hour
|
|
||||||
|
|
||||||
def execute(args)
|
|
||||||
DirectoryItem.refresh!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
module Jobs
|
||||||
|
class DirectoryRefreshDaily < Jobs::Scheduled
|
||||||
|
every 1.hour
|
||||||
|
|
||||||
|
def execute(args)
|
||||||
|
DirectoryItem.refresh_period!(:daily)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -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
|
|
@ -17,11 +17,8 @@ class DirectoryItem < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.refresh!
|
def self.refresh!
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
exec_sql "TRUNCATE TABLE directory_items"
|
|
||||||
period_types.each_key {|p| refresh_period!(p)}
|
period_types.each_key {|p| refresh_period!(p)}
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.refresh_period!(period_type)
|
def self.refresh_period!(period_type)
|
||||||
|
|
||||||
|
@ -36,6 +33,8 @@ class DirectoryItem < ActiveRecord::Base
|
||||||
else 1000.years.ago
|
else 1000.years.ago
|
||||||
end
|
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
|
exec_sql "INSERT INTO directory_items
|
||||||
(period_type, user_id, likes_received, likes_given, topics_entered, days_visited, posts_read, topic_count, post_count)
|
(period_type, user_id, likes_received, likes_given, topics_entered, days_visited, posts_read, topic_count, post_count)
|
||||||
SELECT
|
SELECT
|
||||||
|
@ -74,3 +73,4 @@ class DirectoryItem < ActiveRecord::Base
|
||||||
moderator_action: Post.types[:moderator_action]
|
moderator_action: Post.types[:moderator_action]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue