Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bin/parse_logs
diff options
context:
space:
mode:
authormorgamic@mozilla.com <morgamic@mozilla.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2008-10-15 00:47:54 (GMT)
committer morgamic@mozilla.com <morgamic@mozilla.com@4eb1ac78-321c-0410-a911-ec516a8615a5>2008-10-15 00:47:54 (GMT)
commit06103b543faac6fc978651cd3e4271cb8d45a4ec (patch)
treeadcd84ceec53137c1dee9057871e114c06d2af35 /bin/parse_logs
parenta722e2ede9e3b13483be25df5ded9c64aea33c55 (diff)
Checking in optimization changes for the daily download and total download count script. Bug 456687, r=fligtar, r=xb95.
git-svn-id: http://svn.mozilla.org/addons/trunk@19112 4eb1ac78-321c-0410-a911-ec516a8615a5
Diffstat (limited to 'bin/parse_logs')
-rw-r--r--bin/parse_logs/count_downloads.class.php49
1 files changed, 31 insertions, 18 deletions
diff --git a/bin/parse_logs/count_downloads.class.php b/bin/parse_logs/count_downloads.class.php
index c38544b..b459167 100644
--- a/bin/parse_logs/count_downloads.class.php
+++ b/bin/parse_logs/count_downloads.class.php
@@ -46,6 +46,7 @@ class Count_Downloads {
var $db;
var $totalSkipped = array('blacklist' => 0, 'SJ' => 0, 'NL' => 0, 'CN' => 0);
var $totalCounted = 0;
+ var $counts = array( 'totdown' => array(), 'perday' => array() );
/**
* Initializes download count parser
@@ -76,9 +77,24 @@ class Count_Downloads {
$addon_id = mysql_fetch_array($addon_id_result);
if (!empty($addon_id['addon_id'])) {
- $addon_increment_result = $this->db->query("UPDATE addons SET totaldownloads=totaldownloads+1 WHERE id={$addon_id['addon_id']}", true);
- $this->updateCountsTable($addon_id['addon_id'], $details['unixtime']);
-
+ // update total downloads
+ if (!empty($this->counts['totdown'][$addon_id['addon_id']])) {
+ $this->counts['totdown'][$addon_id['addon_id']] += 1;
+ } else {
+ $this->counts['totdown'][$addon_id['addon_id']] = 1;
+ }
+
+ // update per-day
+ if ( !isset( $this->counts['perday'][$addon_id['addon_id']] ) ) {
+ $this->counts['perday'][$addon_id['addon_id']] = array();
+ }
+
+ if (!empty($this->counts['perday'][$addon_id['addon_id']][date('Y-m-d', $details['unixtime'])])) {
+ $this->counts['perday'][$addon_id['addon_id']][date('Y-m-d', $details['unixtime'])] += 1;
+ } else {
+ $this->counts['perday'][$addon_id['addon_id']][date('Y-m-d', $details['unixtime'])] = 1;
+ }
+
$this->totalCounted++;
outputIfVerbose("[DownloadCounter] Updated count for add-on id: {$addon_id['addon_id']}");
}
@@ -103,24 +119,21 @@ class Count_Downloads {
}
/**
- * Updates or inserts record into counts table for add-on id and date
- */
- function updateCountsTable($addon_id, $unixtime) {
- $date = date('Y-m-d', $unixtime);
- $addon_count_result = $this->db->query("SELECT * FROM download_counts WHERE addon_id='{$addon_id}' AND date='{$date}'");
- $addon_count = mysql_fetch_array($addon_count_result);
-
- if (empty($addon_count))
- $this->db->query("INSERT INTO download_counts (addon_id, count, date) VALUES('{$addon_id}', '1', '{$date}')", true);
- else
- $this->db->query("UPDATE download_counts SET count=count+1 WHERE addon_id='{$addon_id}' AND date='{$date}'", true);
- }
-
- /**
* Callback for after a logfile is parsed.
*/
function logfileParsedCallback() {
-
+ // update total downloads
+ foreach ( $this->counts['totdown'] as $id => $ct ) {
+ $this->db->query("UPDATE addons SET totaldownloads=totaldownloads+{$ct} WHERE id={$id}", true);
+ }
+
+ // now the dailies
+ foreach ( $this->counts['perday'] as $id => $days ) {
+ foreach ( $days as $day => $ct ) {
+ $this->db->query("INSERT INTO download_counts(addon_id, count, date) VALUES({$id}, {$ct}, '{$day}')
+ ON DUPLICATE KEY UPDATE count=count+{$ct}", true);
+ }
+ }
}
}