Skip to content

Commit

Permalink
Compute download numbers for day, week and month.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuykendall committed Jun 30, 2011
1 parent 800d6c7 commit 66e9f13
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 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
Empty file modified script/runner 100644 → 100755
Empty file.

0 comments on commit 66e9f13

Please sign in to comment.