зеркало из https://github.com/mozilla/pjs.git
Checked in v1 modifications to total counts to prevent loss of accuracy.
This commit is contained in:
Родитель
4c02b9971e
Коммит
7e5af16943
|
@ -103,7 +103,26 @@ switch ($action) {
|
||||||
* Update all total download counts.
|
* Update all total download counts.
|
||||||
*/
|
*/
|
||||||
case 'total':
|
case 'total':
|
||||||
|
|
||||||
|
// Get the max dID from downloads so we don't miscount hits
|
||||||
|
// that occur while the update query is running.
|
||||||
|
$max_sql = "
|
||||||
|
SELECT
|
||||||
|
MAX(dID) as max_id
|
||||||
|
FROM
|
||||||
|
downloads
|
||||||
|
";
|
||||||
|
|
||||||
|
$max_result = mysql_query($max_sql, $connection)
|
||||||
|
or trigger_error('MySQL Error '.mysql_errno().': '.mysql_error()."",
|
||||||
|
E_USER_NOTICE);
|
||||||
|
|
||||||
|
$max_row = mysql_fetch_array($max_result,MYSQL_ASSOC);
|
||||||
|
|
||||||
|
$max_id = $max_row['max_id'];
|
||||||
|
|
||||||
// Get uncounted hits from the download table.
|
// Get uncounted hits from the download table.
|
||||||
|
// We only select counts for dID < max_id for accuracy.
|
||||||
$uncounted_hits_sql = "
|
$uncounted_hits_sql = "
|
||||||
SELECT
|
SELECT
|
||||||
downloads.ID as ID,
|
downloads.ID as ID,
|
||||||
|
@ -111,7 +130,8 @@ switch ($action) {
|
||||||
FROM
|
FROM
|
||||||
downloads
|
downloads
|
||||||
WHERE
|
WHERE
|
||||||
`counted`=0
|
`counted`=0 AND
|
||||||
|
dID <= {$max_id}
|
||||||
GROUP BY
|
GROUP BY
|
||||||
downloads.ID
|
downloads.ID
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
@ -135,7 +155,7 @@ switch ($action) {
|
||||||
|
|
||||||
foreach ($uncounted_hits as $id=>$hits) {
|
foreach ($uncounted_hits as $id=>$hits) {
|
||||||
$uncounted_update_sql = "
|
$uncounted_update_sql = "
|
||||||
UPDATE `main` SET `TotalDownloads`=`TotalDownloads`+{$hits} WHERE `ID`='{$id}'
|
UPDATE `main` SET `TotalDownloads`=`TotalDownloads`+{$hits} WHERE `ID`={$id}
|
||||||
";
|
";
|
||||||
$uncounted_update_result = mysql_query($uncounted_update_sql, $connection)
|
$uncounted_update_result = mysql_query($uncounted_update_sql, $connection)
|
||||||
or trigger_error('MySQL Error '.mysql_errno().': '.mysql_error()."",
|
or trigger_error('MySQL Error '.mysql_errno().': '.mysql_error()."",
|
||||||
|
@ -146,21 +166,21 @@ switch ($action) {
|
||||||
// If we get here, we've counted everything and we can mark stuff for
|
// If we get here, we've counted everything and we can mark stuff for
|
||||||
// deletion.
|
// deletion.
|
||||||
//
|
//
|
||||||
// Mark the downloads we just counted as counted if:
|
// Mark the downloads we just counted as counted if it has a key lower
|
||||||
// a) it is a day count that is more than 8 days old
|
// than max_id, because all keys lower than max_id have been counted above
|
||||||
// b) it is a download log that has not been counted
|
|
||||||
//
|
|
||||||
// We may lose a couple counts, theoretically, but it's negligible - we're not
|
|
||||||
// NASA (yes, THE NASA).
|
|
||||||
$counted_update_sql = "
|
$counted_update_sql = "
|
||||||
UPDATE
|
UPDATE
|
||||||
`downloads`
|
`downloads`
|
||||||
SET
|
SET
|
||||||
`counted`=1
|
`counted`=1
|
||||||
|
WHERE
|
||||||
|
dID <= {$max_id}
|
||||||
";
|
";
|
||||||
$counted_update_result = mysql_query($counted_update_sql, $connection)
|
$counted_update_result = mysql_query($counted_update_sql, $connection)
|
||||||
or trigger_error('MySQL Error '.mysql_errno().': '.mysql_error()."",
|
or trigger_error('MySQL Error '.mysql_errno().': '.mysql_error()."",
|
||||||
E_USER_NOTICE);
|
E_USER_NOTICE);
|
||||||
|
} else {
|
||||||
|
$affected_rows = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче