Skip to content

Commit f0efdcb

Browse files
committed
Add style reporting
1 parent dd0677c commit f0efdcb

File tree

7 files changed

+105
-29
lines changed

7 files changed

+105
-29
lines changed

Diff for: app/controllers/styles_controller.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class StylesController < ApplicationController
88

99
cache_sweeper :style_sweeper
1010

11-
protect_from_forgery :except => [:show, :js, :opera_css, :ie_css, :chrome_json, :browse]
11+
protect_from_forgery :except => [:show, :js, :opera_css, :ie_css, :chrome_json, :browse, :report]
1212

1313
$bad_content_subcategories = ["keezmovies", "xvideos", "jizzhut", "pornhub", "redtube", "tube8", "xnxx", "youjizz", "geisha-porn", "4tube", "xhamster", "youporn", "pussy", "imagefap", "pornbits", "xvideosadult", "youskbe", "moez-m", "dokidokibox", "emflix", "erogeba", "eromate", "xxeronetxx", "exploader", "hardsextube", "iqoo", "lovemake", "pornhost", "shufuni", "slutload", "spankwire", "xxxblog", "xvideosmovie", "free-sexvideosfc2", "yaaabooking", "yvhmovie", "oshirimania", "fakku", "e-hentai", "skins", "megaporn", "pussytorrents", "empflix", "xvideos-userporn", "xvideos-porn", "xvideos-collector", "exhentai", "sextube", "yobt", "asstr", "scor", "pornotube", "pornbb", "iafd", "artinude", "motherless", "keyboardporn", "empornium", "eporner", "freeporn", "fritchy", "lettherebeporn", "literotica", "masterporn", "mywebporno", "peniscult", "saff", "porn-w", "pornerbros", "porntown", "sexotorrent", "userporn", "vintage-erotica-forum", "wkdporn", "xxx-tracker", "livejasmin", "myfreecams", "cheggit", "dumparump", "fapomatic", "playboy", "bareback", "brazzers", "hentairules", "h-zip", "sankakucomplex", "gelbooru", "konachan", "donmai", "gz-loader", "pinktower", "artemisweb", "suomi-neito", "tokyo-tube", "nukistream", "elog-ch", "adultghibli", "fleshbot", "ascii2d", "doujin-loli-school", "daimajin", "chaturbate", "cam4", "danshiryo", "yuvutu", "mcstories", "storiesonline", "bestgfe", "stripclublist", "fuskator", "4gifs", "amateurindex", "freeones", "playboy", "adultfanfiction", "hi5", "minkch", "yande", "sexinsex", "eroino", "perfectgirls", "cpz", "ecchi", "eromodels", "erolight", "erolash", "nijie", "okazu24", "bravoteens", "tblop", "elephanttube", "pumbaporn", "pinkworld", "zegaporn", "abcpornsearch", "forhertube", "wtchporn", "1000mg", "sexfotka", 'yiff', 'fetlife', 'rule34', 'pornolab', 'thiendia', 'fusker', 'e621', 'paheal', 'femjoy', 'rei-ayanami', 'kmlg', 'anidub', 'ipmart-forum', 'hentaiverse', 'cinenovinhas', 'mallandrinhas', 'dl-hentaimanga']
1414
$tld_specific_bad_domains = ["dmm.co.jp"]
@@ -678,12 +678,17 @@ def reviewable
678678
@page_title = "Reviewable styles (#{@styles.empty? ? 0 : @styles.total_entries})"
679679
render :action => 'browse'
680680
end
681-
681+
682+
def report
683+
id = params[:idUrl].split('/').last
684+
Style.record_report(id, request.remote_ip)
685+
render :nothing => true, :status => 200
686+
end
682687

683688
protected
684689

685690
def public_action?
686-
['show', 'show_redirect', 'install', 'search_url', 'search_text', 'search', 'browse_r', 'browse', 'graveyard', 'updated', 'js', 'opera_css', 'ie_css', 'chrome_json', 'proxomitron', 'by_user', 'expire_by_id', 'screenshotable', 'automation_page', 'test'].include?(action_name)
691+
['show', 'show_redirect', 'install', 'search_url', 'search_text', 'search', 'browse_r', 'browse', 'graveyard', 'updated', 'js', 'opera_css', 'ie_css', 'chrome_json', 'proxomitron', 'by_user', 'expire_by_id', 'screenshotable', 'automation_page', 'test', 'report'].include?(action_name)
687692
end
688693

689694
def admin_action?

Diff for: app/models/style.rb

+4
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ def self.increment_installs(style_id, source, ip)
530530
Style.connection.execute("INSERT IGNORE INTO daily_install_counts (style_id, ip, source) VALUES (#{Style.connection.quote_string(style_id)}, '#{Style.connection.quote_string(ip)}', '#{Style.connection.quote_string(source)}');")
531531
end
532532

533+
def self.record_report(style_id, ip)
534+
Style.connection.execute("INSERT IGNORE INTO daily_report_counts (style_id, ip) VALUES (#{Style.connection.quote_string(style_id)}, '#{Style.connection.quote_string(ip)}');")
535+
end
536+
533537
# returns an array of the namespace urls for this style, empty array if none, or null if parse error
534538
def calculate_namespaces
535539
namespaces = []

Diff for: config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
get 'style/show/:id' => 'styles#show_redirect'
7878
get 'style/raw/:id' => 'styles#show', :format => 'css'
7979
get 'styles/raw/:id' => 'styles#show', :format => 'css'
80+
post 'report' => 'styles#report'
8081

8182
get 'stylish' => 'index#index'
8283
get 'firstrun' => 'index#firstrun'

Diff for: db/migrate/20141106175043_create_style_reports.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateStyleReports < ActiveRecord::Migration
2+
def change
3+
create_table :daily_report_counts do |t|
4+
t.integer :style_id, :null => false
5+
t.string :ip, :limit => 15, :null => false
6+
end
7+
add_index :daily_report_counts, [:style_id, :ip], :unique => true
8+
execute 'alter table daily_report_counts add column report_date timestamp not null default CURRENT_TIMESTAMP'
9+
end
10+
end

Diff for: db/structure.sql

+65-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- MySQL dump 10.13 Distrib 5.5.38, for debian-linux-gnu (x86_64)
1+
-- MySQL dump 10.13 Distrib 5.6.19, for debian-linux-gnu (x86_64)
22
--
33
-- Host: localhost Database: userstyles
44
-- ------------------------------------------------------
5-
-- Server version 5.5.38-0ubuntu0.14.04.1
5+
-- Server version 5.6.19-1~exp1ubuntu2
66

77
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
88
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -51,7 +51,7 @@ CREATE TABLE `GDN_Activity` (
5151
KEY `IX_Activity_Recent` (`NotifyUserID`,`DateUpdated`),
5252
KEY `IX_Activity_Feed` (`NotifyUserID`,`ActivityUserID`,`DateUpdated`),
5353
KEY `IX_Activity_DateUpdated` (`DateUpdated`)
54-
) ENGINE=MyISAM AUTO_INCREMENT=158182 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
54+
) ENGINE=MyISAM AUTO_INCREMENT=159778 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
5555
/*!40101 SET character_set_client = @saved_cs_client */;
5656

5757
--
@@ -238,7 +238,7 @@ CREATE TABLE `GDN_Comment` (
238238
KEY `IX_Comment_1` (`DiscussionID`,`DateInserted`),
239239
KEY `IX_Comment_DateInserted` (`DateInserted`),
240240
FULLTEXT KEY `TX_Comment` (`Body`)
241-
) ENGINE=MyISAM AUTO_INCREMENT=92067 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
241+
) ENGINE=MyISAM AUTO_INCREMENT=92828 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
242242
/*!40101 SET character_set_client = @saved_cs_client */;
243243

244244
--
@@ -268,7 +268,7 @@ CREATE TABLE `GDN_Conversation` (
268268
KEY `FK_Conversation_DateInserted` (`DateInserted`),
269269
KEY `FK_Conversation_UpdateUserID` (`UpdateUserID`),
270270
KEY `IX_Conversation_RegardingID` (`RegardingID`)
271-
) ENGINE=MyISAM AUTO_INCREMENT=5524 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
271+
) ENGINE=MyISAM AUTO_INCREMENT=5578 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
272272
/*!40101 SET character_set_client = @saved_cs_client */;
273273

274274
--
@@ -289,7 +289,7 @@ CREATE TABLE `GDN_ConversationMessage` (
289289
PRIMARY KEY (`MessageID`),
290290
KEY `FK_ConversationMessage_ConversationID` (`ConversationID`),
291291
KEY `FK_ConversationMessage_InsertUserID` (`InsertUserID`)
292-
) ENGINE=MyISAM AUTO_INCREMENT=10570 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
292+
) ENGINE=MyISAM AUTO_INCREMENT=10667 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
293293
/*!40101 SET character_set_client = @saved_cs_client */;
294294

295295
--
@@ -339,7 +339,7 @@ CREATE TABLE `GDN_Discussion` (
339339
KEY `IX_Discussion_DateInserted` (`DateInserted`),
340340
KEY `IX_Discussion_CategoryPages` (`CategoryID`,`DateLastComment`),
341341
FULLTEXT KEY `TX_Discussion` (`Name`,`Body`)
342-
) ENGINE=MyISAM AUTO_INCREMENT=43846 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
342+
) ENGINE=MyISAM AUTO_INCREMENT=44192 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
343343
/*!40101 SET character_set_client = @saved_cs_client */;
344344

345345
--
@@ -368,7 +368,7 @@ CREATE TABLE `GDN_Draft` (
368368
KEY `FK_Draft_DiscussionID` (`DiscussionID`),
369369
KEY `FK_Draft_CategoryID` (`CategoryID`),
370370
KEY `FK_Draft_InsertUserID` (`InsertUserID`)
371-
) ENGINE=MyISAM AUTO_INCREMENT=41636 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
371+
) ENGINE=MyISAM AUTO_INCREMENT=42519 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
372372
/*!40101 SET character_set_client = @saved_cs_client */;
373373

374374
--
@@ -444,7 +444,7 @@ CREATE TABLE `GDN_Log` (
444444
KEY `IX_Log_RecordIPAddress` (`RecordIPAddress`),
445445
KEY `IX_Log_ParentRecordID` (`ParentRecordID`),
446446
KEY `FK_Log_CategoryID` (`CategoryID`)
447-
) ENGINE=InnoDB AUTO_INCREMENT=15273 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
447+
) ENGINE=InnoDB AUTO_INCREMENT=15460 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
448448
/*!40101 SET character_set_client = @saved_cs_client */;
449449

450450
--
@@ -471,7 +471,7 @@ CREATE TABLE `GDN_Media` (
471471
`ForeignID` int(11) DEFAULT NULL,
472472
`ForeignTable` varchar(24) COLLATE utf8_unicode_ci DEFAULT NULL,
473473
PRIMARY KEY (`MediaID`)
474-
) ENGINE=MyISAM AUTO_INCREMENT=9472 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
474+
) ENGINE=MyISAM AUTO_INCREMENT=9657 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
475475
/*!40101 SET character_set_client = @saved_cs_client */;
476476

477477
--
@@ -737,7 +737,7 @@ CREATE TABLE `GDN_User` (
737737
KEY `IX_User_Email` (`Email`),
738738
KEY `IX_User_DateLastActive` (`DateLastActive`),
739739
KEY `IX_User_DateInserted` (`DateInserted`)
740-
) ENGINE=MyISAM AUTO_INCREMENT=160809 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
740+
) ENGINE=MyISAM AUTO_INCREMENT=161199 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
741741
/*!40101 SET character_set_client = @saved_cs_client */;
742742

743743
--
@@ -1355,6 +1355,23 @@ CREATE TABLE `daily_install_counts` (
13551355
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
13561356
/*!40101 SET character_set_client = @saved_cs_client */;
13571357

1358+
--
1359+
-- Table structure for table `daily_report_counts`
1360+
--
1361+
1362+
DROP TABLE IF EXISTS `daily_report_counts`;
1363+
/*!40101 SET @saved_cs_client = @@character_set_client */;
1364+
/*!40101 SET character_set_client = utf8 */;
1365+
CREATE TABLE `daily_report_counts` (
1366+
`id` int(11) NOT NULL AUTO_INCREMENT,
1367+
`style_id` int(11) NOT NULL,
1368+
`ip` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
1369+
`report_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
1370+
PRIMARY KEY (`id`),
1371+
UNIQUE KEY `index_daily_report_counts_on_style_id_and_ip` (`style_id`,`ip`)
1372+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1373+
/*!40101 SET character_set_client = @saved_cs_client */;
1374+
13581375
--
13591376
-- Table structure for table `delayed_jobs`
13601377
--
@@ -1376,7 +1393,7 @@ CREATE TABLE `delayed_jobs` (
13761393
`updated_at` datetime DEFAULT NULL,
13771394
`queue` varchar(255) DEFAULT NULL,
13781395
PRIMARY KEY (`id`)
1379-
) ENGINE=MyISAM AUTO_INCREMENT=1722832 DEFAULT CHARSET=latin1;
1396+
) ENGINE=MyISAM AUTO_INCREMENT=1771309 DEFAULT CHARSET=latin1;
13801397
/*!40101 SET character_set_client = @saved_cs_client */;
13811398

13821399
--
@@ -1423,11 +1440,11 @@ DROP TABLE IF EXISTS `precalculated_warnings`;
14231440
CREATE TABLE `precalculated_warnings` (
14241441
`id` int(11) NOT NULL AUTO_INCREMENT,
14251442
`style_id` int(11) NOT NULL,
1426-
`warning_type` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1427-
`detail` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
1443+
`warning_type` varchar(20) NOT NULL,
1444+
`detail` varchar(1000) NOT NULL,
14281445
PRIMARY KEY (`id`),
14291446
KEY `index_precalculated_warnings_on_style_id` (`style_id`)
1430-
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1447+
) ENGINE=InnoDB AUTO_INCREMENT=14383 DEFAULT CHARSET=utf8;
14311448
/*!40101 SET character_set_client = @saved_cs_client */;
14321449

14331450
--
@@ -1469,7 +1486,7 @@ CREATE TABLE `screenshots` (
14691486
`path` varchar(50) NOT NULL,
14701487
PRIMARY KEY (`id`),
14711488
KEY `style_id` (`style_id`)
1472-
) ENGINE=MyISAM AUTO_INCREMENT=12567 DEFAULT CHARSET=latin1;
1489+
) ENGINE=MyISAM AUTO_INCREMENT=12827 DEFAULT CHARSET=latin1;
14731490
/*!40101 SET character_set_client = @saved_cs_client */;
14741491

14751492
--
@@ -1518,7 +1535,7 @@ CREATE TABLE `style_codes` (
15181535
`code` mediumtext NOT NULL,
15191536
PRIMARY KEY (`id`),
15201537
UNIQUE KEY `style_id` (`style_id`)
1521-
) ENGINE=MyISAM AUTO_INCREMENT=106176 DEFAULT CHARSET=utf8;
1538+
) ENGINE=MyISAM AUTO_INCREMENT=107197 DEFAULT CHARSET=utf8;
15221539
/*!40101 SET character_set_client = @saved_cs_client */;
15231540

15241541
--
@@ -1538,7 +1555,7 @@ CREATE TABLE `style_install_counts` (
15381555
KEY `id` (`id`),
15391556
KEY `style_id` (`style_id`),
15401557
KEY `date` (`date`)
1541-
) ENGINE=MyISAM AUTO_INCREMENT=31874082 DEFAULT CHARSET=utf8;
1558+
) ENGINE=MyISAM AUTO_INCREMENT=32365967 DEFAULT CHARSET=utf8;
15421559
/*!40101 SET character_set_client = @saved_cs_client */;
15431560

15441561
--
@@ -1556,6 +1573,26 @@ CREATE TABLE `style_install_counts_archive` (
15561573
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
15571574
/*!40101 SET character_set_client = @saved_cs_client */;
15581575

1576+
--
1577+
-- Table structure for table `style_install_counts_new`
1578+
--
1579+
1580+
DROP TABLE IF EXISTS `style_install_counts_new`;
1581+
/*!40101 SET @saved_cs_client = @@character_set_client */;
1582+
/*!40101 SET character_set_client = utf8 */;
1583+
CREATE TABLE `style_install_counts_new` (
1584+
`id` int(11) NOT NULL AUTO_INCREMENT,
1585+
`style_id` int(11) NOT NULL DEFAULT '0',
1586+
`date` date NOT NULL DEFAULT '0000-00-00',
1587+
`install_count` int(11) NOT NULL DEFAULT '0',
1588+
`source` varchar(10) NOT NULL,
1589+
UNIQUE KEY `unique_style_source_and_date` (`style_id`,`date`,`source`),
1590+
KEY `id` (`id`),
1591+
KEY `style_id` (`style_id`),
1592+
KEY `date` (`date`)
1593+
) ENGINE=InnoDB AUTO_INCREMENT=22088723 DEFAULT CHARSET=utf8;
1594+
/*!40101 SET character_set_client = @saved_cs_client */;
1595+
15591596
--
15601597
-- Table structure for table `style_section_rules`
15611598
--
@@ -1570,7 +1607,7 @@ CREATE TABLE `style_section_rules` (
15701607
`rule_value` varchar(1000) CHARACTER SET utf8 NOT NULL,
15711608
PRIMARY KEY (`id`),
15721609
KEY `style_section_rules_style_section_id` (`style_section_id`)
1573-
) ENGINE=MyISAM AUTO_INCREMENT=1412165 DEFAULT CHARSET=latin1;
1610+
) ENGINE=MyISAM AUTO_INCREMENT=1460969 DEFAULT CHARSET=latin1;
15741611
/*!40101 SET character_set_client = @saved_cs_client */;
15751612

15761613
--
@@ -1588,7 +1625,7 @@ CREATE TABLE `style_sections` (
15881625
`css` mediumtext CHARACTER SET utf8 NOT NULL,
15891626
PRIMARY KEY (`id`),
15901627
KEY `style_sections_style_id` (`style_id`)
1591-
) ENGINE=MyISAM AUTO_INCREMENT=910374 DEFAULT CHARSET=latin1;
1628+
) ENGINE=MyISAM AUTO_INCREMENT=930032 DEFAULT CHARSET=latin1;
15921629
/*!40101 SET character_set_client = @saved_cs_client */;
15931630

15941631
--
@@ -1609,7 +1646,7 @@ CREATE TABLE `style_setting_options` (
16091646
PRIMARY KEY (`id`),
16101647
UNIQUE KEY `ix_style_setting_id_install_key` (`style_setting_id`,`install_key`),
16111648
KEY `style_option_values_style_option_id` (`style_setting_id`)
1612-
) ENGINE=MyISAM AUTO_INCREMENT=1406892 DEFAULT CHARSET=utf8;
1649+
) ENGINE=MyISAM AUTO_INCREMENT=1430378 DEFAULT CHARSET=utf8;
16131650
/*!40101 SET character_set_client = @saved_cs_client */;
16141651

16151652
--
@@ -1628,7 +1665,7 @@ CREATE TABLE `style_settings` (
16281665
`setting_type` varchar(10) NOT NULL,
16291666
PRIMARY KEY (`id`),
16301667
UNIQUE KEY `ix_style_options_style_id_name` (`style_id`,`install_key`)
1631-
) ENGINE=MyISAM AUTO_INCREMENT=361364 DEFAULT CHARSET=utf8;
1668+
) ENGINE=MyISAM AUTO_INCREMENT=370634 DEFAULT CHARSET=utf8;
16321669
/*!40101 SET character_set_client = @saved_cs_client */;
16331670

16341671
--
@@ -1688,7 +1725,7 @@ CREATE TABLE `styles` (
16881725
KEY `subcategory` (`subcategory`),
16891726
KEY `popularity_score` (`popularity_score`),
16901727
KEY `admin_delete_reason_id` (`admin_delete_reason_id`)
1691-
) ENGINE=MyISAM AUTO_INCREMENT=105928 DEFAULT CHARSET=utf8;
1728+
) ENGINE=InnoDB AUTO_INCREMENT=106952 DEFAULT CHARSET=utf8;
16921729
/*!40101 SET character_set_client = @saved_cs_client */;
16931730

16941731
--
@@ -1708,7 +1745,7 @@ CREATE TABLE `user_authenticators` (
17081745
UNIQUE KEY `provider_identifier` (`provider_identifier`),
17091746
KEY `user_id_fk` (`user_id`),
17101747
KEY `provider_provider_identifier_ix` (`provider`,`provider_identifier`)
1711-
) ENGINE=MyISAM AUTO_INCREMENT=73894 DEFAULT CHARSET=utf8;
1748+
) ENGINE=MyISAM AUTO_INCREMENT=75531 DEFAULT CHARSET=utf8;
17121749
/*!40101 SET character_set_client = @saved_cs_client */;
17131750

17141751
--
@@ -1741,7 +1778,7 @@ CREATE TABLE `users` (
17411778
UNIQUE KEY `unique_login` (`login`),
17421779
KEY `token` (`token`),
17431780
KEY `LUM_User_id` (`LUM_User_id`)
1744-
) ENGINE=MyISAM AUTO_INCREMENT=275041 DEFAULT CHARSET=utf8;
1781+
) ENGINE=MyISAM AUTO_INCREMENT=277486 DEFAULT CHARSET=utf8;
17451782
/*!40101 SET character_set_client = @saved_cs_client */;
17461783
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
17471784

@@ -1753,12 +1790,14 @@ CREATE TABLE `users` (
17531790
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
17541791
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
17551792

1756-
-- Dump completed on 2014-10-05 17:13:28
1793+
-- Dump completed on 2014-11-06 12:19:32
17571794
INSERT INTO schema_migrations (version) VALUES ('20111007022556');
17581795

17591796
INSERT INTO schema_migrations (version) VALUES ('20131104171052');
17601797

17611798
INSERT INTO schema_migrations (version) VALUES ('20141005210800');
17621799

1800+
INSERT INTO schema_migrations (version) VALUES ('20141106175043');
1801+
17631802
INSERT INTO schema_migrations (version) VALUES ('6');
17641803

Diff for: shellscripts/report_counts.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "Starting at `date`" >> ../log/update_report_counts.log
2+
~/cron/db < ./update_report_counts.sql >> ../log/update_report_counts.log 2>&1
3+
echo "Done at `date`" >> ../log/update_report_counts.log

Diff for: shellscripts/report_counts.sql

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- daily reports - anything in the last 24 hours
2+
UPDATE styles SET daily_reports = 0;
3+
UPDATE styles s
4+
JOIN (
5+
SELECT style_id, COUNT(*) c FROM daily_report_counts WHERE report_date >= DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY style_id
6+
) d
7+
ON s.id = d.style_id
8+
SET s.daily_reports = d.c;
9+
10+
-- move anything before yesterday to the historical count table
11+
INSERT IGNORE INTO report_counts
12+
(style_id, report_date, reports)
13+
(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));
14+
DELETE FROM daily_report_counts WHERE report_date < DATE_SUB(CURDATE(), INTERVAL 1 DAY);

0 commit comments

Comments
 (0)