From 66e9f13970e0845c6d53699d58e657927fa310f2 Mon Sep 17 00:00:00 2001 From: Robert Kuykendall Date: Thu, 30 Jun 2011 14:10:51 -0500 Subject: [PATCH] Compute download numbers for day, week and month. --- app/hourly.rb | 37 +++++++++++++++++++++++++++++++++++++ script/runner | 0 2 files changed, 37 insertions(+) create mode 100755 app/hourly.rb mode change 100644 => 100755 script/runner diff --git a/app/hourly.rb b/app/hourly.rb new file mode 100755 index 00000000..dd04b8e9 --- /dev/null +++ b/app/hourly.rb @@ -0,0 +1,37 @@ +class Hourly < ActiveRecord::Base + # Code from example + # post_ids = Post.find(:all, :conditions => ["created_at < ?", 5.minutes.ago]) + # + # if post_ids.size > 0 + # Post.destroy(post_ids) + # puts "#{post_ids.size} posts have been deleted!" + # end + + puts "Start!" + + @items = Item.find(:all, :conditions => ["versions_count > 0"]) + + puts "Processing!" + + @items.each do |item| + item.downloads_day_count = item.downloads.last_day.count + item.downloads_week_count = item.downloads.last_week.count + item.downloads_month_count = item.downloads.last_month.count + item.save + end + + puts "Finished!" + + + # Code from downloads development + # after_filter :calculate_counts + # + # def calculate_counts + # item = Item.find_by_permalink(params[:item_id]) + # item.downloads_day_count = item.downloads.last_day.count + # item.downloads_week_count = item.downloads.last_week.count + # item.downloads_month_count = item.downloads.last_month.count + # item.save + # end + +end diff --git a/script/runner b/script/runner old mode 100644 new mode 100755