Commit 5391262c3091524253368b3736767d62b72fd46a
1 parent
fde9abb3
Exists in
ratings_minor_fixes
and in
4 other branches
init: move jobs to app/jobs
Showing
4 changed files
with
25 additions
and
25 deletions
Show diff stats
... | ... | @@ -0,0 +1,14 @@ |
1 | +class ActivitiesCounterCacheJob | |
2 | + | |
3 | + def perform | |
4 | + person_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Person' ) ) GROUP BY profiles.id;") | |
5 | + organization_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Community' OR profiles.type = 'Enterprise' OR profiles.type = 'Organization' ) ) GROUP BY profiles.id;") | |
6 | + activities_counts = person_activities_counts.entries + organization_activities_counts.entries | |
7 | + activities_counts.each do |count| | |
8 | + update_sql = ApplicationRecord.__send__(:sanitize_sql, ["UPDATE profiles SET activities_count=? WHERE profiles.id=?;", count['count'].to_i, count['id'] ], '') | |
9 | + ApplicationRecord.connection.execute(update_sql) | |
10 | + end | |
11 | + Delayed::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3, :run_at => 1.day.from_now}) | |
12 | + end | |
13 | + | |
14 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +class CreateThumbnailsJob < Struct.new(:class_name, :file_id) | |
2 | + def perform | |
3 | + return unless class_name.constantize.exists?(file_id) | |
4 | + file = class_name.constantize.find(file_id) | |
5 | + file.create_thumbnails | |
6 | + article = Article.where(:image_id => file_id).first | |
7 | + if article | |
8 | + article.touch | |
9 | + end | |
10 | + end | |
11 | +end | ... | ... |
lib/activities_counter_cache_job.rb
... | ... | @@ -1,14 +0,0 @@ |
1 | -class ActivitiesCounterCacheJob | |
2 | - | |
3 | - def perform | |
4 | - person_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Person' ) ) GROUP BY profiles.id;") | |
5 | - organization_activities_counts = ApplicationRecord.connection.execute("SELECT profiles.id, count(action_tracker.id) as count FROM profiles LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id WHERE (action_tracker.created_at >= #{ApplicationRecord.connection.quote(ActionTracker::Record::RECENT_DELAY.days.ago.to_s(:db))}) AND ( (profiles.type = 'Community' OR profiles.type = 'Enterprise' OR profiles.type = 'Organization' ) ) GROUP BY profiles.id;") | |
6 | - activities_counts = person_activities_counts.entries + organization_activities_counts.entries | |
7 | - activities_counts.each do |count| | |
8 | - update_sql = ApplicationRecord.__send__(:sanitize_sql, ["UPDATE profiles SET activities_count=? WHERE profiles.id=?;", count['count'].to_i, count['id'] ], '') | |
9 | - ApplicationRecord.connection.execute(update_sql) | |
10 | - end | |
11 | - Delayed::Job.enqueue(ActivitiesCounterCacheJob.new, {:priority => -3, :run_at => 1.day.from_now}) | |
12 | - end | |
13 | - | |
14 | -end |
lib/create_thumbnails_job.rb
... | ... | @@ -1,11 +0,0 @@ |
1 | -class CreateThumbnailsJob < Struct.new(:class_name, :file_id) | |
2 | - def perform | |
3 | - return unless class_name.constantize.exists?(file_id) | |
4 | - file = class_name.constantize.find(file_id) | |
5 | - file.create_thumbnails | |
6 | - article = Article.where(:image_id => file_id).first | |
7 | - if article | |
8 | - article.touch | |
9 | - end | |
10 | - end | |
11 | -end |