-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd0677c
commit f0efdcb
Showing
7 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateStyleReports < ActiveRecord::Migration | ||
def change | ||
create_table :daily_report_counts do |t| | ||
t.integer :style_id, :null => false | ||
t.string :ip, :limit => 15, :null => false | ||
end | ||
add_index :daily_report_counts, [:style_id, :ip], :unique => true | ||
execute 'alter table daily_report_counts add column report_date timestamp not null default CURRENT_TIMESTAMP' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
echo "Starting at `date`" >> ../log/update_report_counts.log | ||
~/cron/db < ./update_report_counts.sql >> ../log/update_report_counts.log 2>&1 | ||
echo "Done at `date`" >> ../log/update_report_counts.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- daily reports - anything in the last 24 hours | ||
UPDATE styles SET daily_reports = 0; | ||
UPDATE styles s | ||
JOIN ( | ||
SELECT style_id, COUNT(*) c FROM daily_report_counts WHERE report_date >= DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY style_id | ||
) d | ||
ON s.id = d.style_id | ||
SET s.daily_reports = d.c; | ||
|
||
-- move anything before yesterday to the historical count table | ||
INSERT IGNORE INTO report_counts | ||
(style_id, report_date, reports) | ||
(SELECT style_id, DATE(report_date), COUNT(*) FROM daily_report_counts WHERE report_date < DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY style_id, DATE(report_date)); | ||
DELETE FROM daily_report_counts WHERE report_date < DATE_SUB(CURDATE(), INTERVAL 1 DAY); |