Skip to content
Permalink
Browse files

better log ordering; updates #931

  • Loading branch information...
following5 committed Mar 14, 2016
1 parent cee6386 commit fb18fe0276d74e26e0d0781c404a3826d57a6d58
@@ -798,6 +798,32 @@ function dbv_150() // add history of reported waypoints
) ENGINE=MyISAM");
}
function dbv_151() // new date field for ordering logs
{
if (!sql_field_exists('cache_logs', 'order_date'))
{
sql("ALTER TABLE `cache_logs` ADD COLUMN `order_date` datetime NOT NULL AFTER `date`");
sql("
UPDATE `cache_logs`
SET `order_date` = IF(RIGHT(`date`, 8) <> '00:00:00' OR `date` > `date_created`, `date`,
IF(LEFT(`date_created`, 10) = LEFT(`date`, 10), `date_created`,
CONCAT(LEFT(`date`, 11), '23:59:58')))
");
}
if (!sql_index_exists('cache_logs', 'order_date'))
sql("ALTER TABLE `cache_logs` ADD INDEX `order_date` (`cache_id`,`order_date`,`date_created`,`id`)");
if (!sql_field_exists('cache_logs_archived', 'order_date'))
{
sql("ALTER TABLE `cache_logs_archived` ADD COLUMN `order_date` datetime NOT NULL AFTER `date`");
sql("
UPDATE `cache_logs_archived`
SET `order_date` = IF(RIGHT(`date`, 8) <> '00:00:00' OR `date` > `date_created`, `date`,
IF(LEFT(`date_created`, 10) = LEFT(`date`, 10), `date_created`,
CONCAT(LEFT(`date`, 11), '23:59:58')))
");
}
}
// When adding new mutations, take care that they behave well if run multiple
// times. This improves robustness of database versioning.
//
@@ -361,8 +361,8 @@
END IF;
UPDATE `caches` SET
`needs_maintenance` = (SELECT GREATEST(0,`needs_maintenance`-1) FROM `cache_logs` WHERE `cache_logs`.`cache_id`=nCacheID AND (`cache_logs`.`needs_maintenance`>0 OR `cache_logs`.`type` In (9,13,14)) ORDER BY `date` DESC, `date_created` DESC, `id` DESC LIMIT 1),
`listing_outdated` = (SELECT GREATEST(0,`listing_outdated`-1) FROM `cache_logs` WHERE `cache_logs`.`cache_id`=nCacheID AND (`cache_logs`.`listing_outdated`>0 OR `cache_logs`.`type` In (9,13,14)) ORDER BY `date` DESC, `date_created` DESC, `id` DESC LIMIT 1)
`needs_maintenance` = (SELECT GREATEST(0,`needs_maintenance`-1) FROM `cache_logs` WHERE `cache_logs`.`cache_id`=nCacheID AND (`cache_logs`.`needs_maintenance`>0 OR `cache_logs`.`type` In (9,13,14)) ORDER BY `order_date` DESC, `date_created` DESC, `id` DESC LIMIT 1),
`listing_outdated` = (SELECT GREATEST(0,`listing_outdated`-1) FROM `cache_logs` WHERE `cache_logs`.`cache_id`=nCacheID AND (`cache_logs`.`listing_outdated`>0 OR `cache_logs`.`type` In (9,13,14)) ORDER BY `order_date` DESC, `date_created` DESC, `id` DESC LIMIT 1)
/* same sorting order as in caches::getListingOutdatedLogUrl() */
WHERE `caches`.`cache_id`=nCacheId;
END IF;
@@ -1090,9 +1090,13 @@
/* dont overwrite date values while XML client is running */
IF ISNULL(@XMLSYNC) OR @XMLSYNC!=1 THEN
SET NEW.`date_created`=NOW();
SET NEW.`entry_last_modified`=NOW();
SET NEW.`last_modified`=NOW();
SET NEW.`log_last_modified`=NEW.`last_modified`;
SET NEW.`entry_last_modified`=NEW.`date_created`;
SET NEW.`last_modified`=NEW.`date_created`;
SET NEW.`log_last_modified`=NEW.`date_created`;
SET NEW.`order_date`=
IF(RIGHT(NEW.`date`, 8) <> '00:00:00' OR NEW.`date` > NEW.`date_created`, NEW.`date`,
IF(LEFT(NEW.`date_created`, 10) = LEFT(NEW.`date`, 10), NEW.`date_created`,
CONCAT(LEFT(NEW.`date`, 11), '23:59:58')));
END IF;
IF ISNULL(NEW.`uuid`) OR NEW.`uuid`='' THEN
@@ -1154,6 +1158,12 @@
NEW.`text`!=BINARY OLD.`text` OR
NEW.`text_html`!=OLD.`text_html` THEN
SET NEW.`log_last_modified`=NEW.`date_created`;
SET NEW.`order_date`=
IF(RIGHT(NEW.`date`, 8) <> '00:00:00' OR NEW.`date` > NEW.`date_created`, NEW.`date`,
IF(LEFT(NEW.`date_created`, 10) = LEFT(NEW.`date`, 10), NEW.`date_created`,
CONCAT(LEFT(NEW.`date`, 11), '23:59:58')));
/* log versioning to allow log vandalism restore (except pictures);
* optimize storage space by ignoring quick-corrections of logs
*/
@@ -13,6 +13,7 @@ CREATE TABLE `cache_logs` (
`type` tinyint(3) unsigned NOT NULL,
`oc_team_comment` tinyint(1) NOT NULL default '0',
`date` datetime NOT NULL,
`order_date` datetime NOT NULL,
`needs_maintenance` tinyint(1) NOT NULL default '0',
`listing_outdated` tinyint(1) NOT NULL default '0',
`text` mediumtext NOT NULL,
@@ -30,5 +31,6 @@ CREATE TABLE `cache_logs` (
KEY `date_created` (`date_created`),
KEY `user_id` (`user_id`,`cache_id`),
KEY `cache_id` (`cache_id`,`user_id`),
KEY `date` (`cache_id`,`date`,`date_created`)
KEY `date` (`cache_id`,`date`,`date_created`),
KEY `order_date` (`cache_id`,`order_date`,`date_created`,`id`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
@@ -13,6 +13,7 @@ CREATE TABLE `cache_logs_archived` (
`type` tinyint(3) unsigned NOT NULL,
`oc_team_comment` tinyint(1) NOT NULL default '0',
`date` datetime NOT NULL,
`order_date` datetime NOT NULL,
`needs_maintenance` tinyint(1) NOT NULL default '0',
`listing_outdated` tinyint(1) NOT NULL default '0',
`text` mediumtext NOT NULL,
@@ -244,7 +244,7 @@ function getListingOutdatedLogUrl()
SELECT `id`, `listing_outdated`
FROM `cache_logs`
WHERE `cache_id`='&1' AND `listing_outdated`>0
ORDER BY `date` DESC, `date_created` DESC, `id` DESC",
ORDER BY `order_date` DESC, `date_created` DESC, `id` DESC",
// same sorting order as in DB function sp_update_logstat()
$this->getCacheId()
);
@@ -391,6 +391,7 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false, $protect_
`cache_logs`.`id` AS `id`,
`cache_logs`.`uuid` AS `uuid`,
`cache_logs`.`date` AS `date`,
`cache_logs`.`order_date` AS `order_date`,
`cache_logs`.`entry_last_modified`,
DATEDIFF(`cache_logs`.`entry_last_modified`, `cache_logs`.`date_created`) >= 1 AS `late_modified`,
substr(`cache_logs`.`date`,12) AS `time`, /* 00:00:01 = 00:00 logged, 00:00:00 = no time */
@@ -409,7 +410,7 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false, $protect_
LEFT JOIN `cache_rating` ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id` AND `cache_logs`.`user_id`=`cache_rating`.`user_id` AND `cache_logs`.`date`=`cache_rating`.`rating_date`
".$addjoin."
WHERE `cache_logs`.`cache_id`='&1'
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`date_created` DESC
ORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `id` DESC
LIMIT &2, &3", $cacheid, $start+0, $count+0);
$logs = array();
@@ -427,7 +428,7 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false, $protect_
$rLog['text'] = use_current_protocol_in_html($rLog['text']);
$newcoord = false;
while ($coordpos < count($coords) && $coords[$coordpos]['date'] > $rLog['date']) {
while ($coordpos < count($coords) && $coords[$coordpos]['date'] > $rLog['order_date']) {
if (!$newcoord) $newcoord = $coords[$coordpos];
++$coordpos;
}
@@ -452,9 +453,9 @@ static function getLogsArray($cacheid, $start, $count, $deleted=false, $protect_
}
sql_free_result($rsLogs);
if ($coord_changes && count($logs)) {
if ($coord_changes) {
$original = count($coords)-1;
$lastlogdate = $logs[count($logs)-1]['date'];
$lastlogdate = $logs[count($logs)-1]['order_date'];
while ($original > 0 && $coords[$original-1]['date'] < $lastlogdate)
--$original;
$coord = new coordinate($coords[$original]['latitude'], $coords[$original]['longitude']);
@@ -117,7 +117,7 @@ function get_logpics($purpose, $userid=0, $cacheid=0)
$join_caches
$join_cachestatus
WHERE `object_type`=1 AND `logs`.`user_id`='&1' AND NOT `spoiler`
ORDER BY `logs`.`date` DESC", $userid);
ORDER BY `logs`.`order_date` DESC", $userid);
break;
case LOGPICS_FOR_MYHOME_GALLERY:
@@ -128,7 +128,7 @@ function get_logpics($purpose, $userid=0, $cacheid=0)
FROM `pictures` AS `pics`
$join_logs
WHERE `object_type`=1 AND `logs`.`user_id`='&1'
ORDER BY `logs`.`date` DESC", $login->userid);
ORDER BY `logs`.`order_date` DESC", $login->userid);
break;
@@ -157,7 +157,7 @@ function get_logpics($purpose, $userid=0, $cacheid=0)
$join_user
WHERE `object_type`=1 AND `logs`.`cache_id`='&1'
AND NOT (`data_license` IN ('&2','&3'))
ORDER BY `logs`.`date` DESC",
ORDER BY `logs`.`order_date` DESC",
$cacheid, NEW_DATA_LICENSE_ACTIVELY_DECLINED, NEW_DATA_LICENSE_PASSIVELY_DECLINED);
break;
@@ -360,8 +360,9 @@ function search_output()
`cache_logs`.`cache_id`='&1' AND
`user`.`user_id`".$user_operator."'&2'
ORDER BY
`cache_logs`.`date` DESC,
`cache_logs`.`date_created` DESC"
`cache_logs`.`order_date` DESC,
`cache_logs`.`date_created` DESC,
`cache_logs`.`id` DESC"
. $limit,
$r['cacheid'], $user_id
);
@@ -88,7 +88,7 @@ function search_output()
FROM `cache_logs`, `log_types`
WHERE `cache_logs`.`cache_id`='" . sql_escape($rCache['cache_id']) . "'
AND `log_types`.`id`=`cache_logs`.`type`" . $ownlogs . "
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`date_created` DESC
ORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `cache_logs`.`id` DESC
LIMIT 6";
$rs = sql_slave($sql);
$rCache['logs'] = sql_fetch_assoc_table($rs);
@@ -155,7 +155,10 @@ function search_output()
WHERE
`cache_logs`.`cache_id`=&1
ORDER BY
`cache_logs`.`date` DESC LIMIT 20",
`cache_logs`.`order_date` DESC,
`cache_logs`.`date_created` DESC,
`cache_logs`.`id` DESC
DESC LIMIT 20",
$r['cacheid'], $opt['template']['locale']);
while ($rLog = sql_fetch_array($rsLogs))
@@ -40,7 +40,7 @@
LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
LEFT JOIN `cache_rating` ON `cache_rating`.`cache_id`=`caches`.`cache_id` AND `cache_rating`.`user_id`=`cache_logs`.`user_id` AND `cache_rating`.`rating_date`=`cache_logs`.`date`
WHERE `cache_logs`.`user_id`='&1'
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`date_created` DESC
ORDER BY `cache_logs`.`order_date` DESC, `cache_logs`.`date_created` DESC, `cache_logs`.`id` DESC
LIMIT 10", $login->userid));
$tpl->assign('morelogs', sql_value("SELECT FOUND_ROWS()", 0) > 10);
sql_foundrows_done();
@@ -55,7 +55,7 @@
MAX(`cache_logs`.`date`) AS `lastlog`,
(SELECT `type` FROM `cache_logs` `cl2`
WHERE `cl2`.`cache_id`=`caches`.`cache_id`
ORDER BY `date` DESC,`id` DESC LIMIT 1) AS `lastlog_type`
ORDER BY `order_date` DESC, `date_created` DESC, `id` DESC LIMIT 1) AS `lastlog_type`
FROM `caches`
LEFT JOIN `stat_caches` ON `stat_caches`.`cache_id`=`caches`.`cache_id`
LEFT JOIN `cache_logs` ON `cache_logs`.`cache_id`=`caches`.`cache_id`
@@ -41,7 +41,7 @@
$paging = true;
$newLogsPerCountry = false;
$caches_logged = array();
$orderByDate = '`cache_logs`.`date` DESC, ';
$orderByDate = '`cache_logs`.`order_date` DESC, ';
if ($show_own_logs) $urlparams = '&ownlogs=1';
$logselection = 3;
}
@@ -56,7 +56,7 @@
$logcount = 100;
$paging = true;
$newLogsPerCountry = false;
$orderByDate = '`cache_logs`.`date` DESC, ';
$orderByDate = '`cache_logs`.`order_date` DESC, ';
$logselection = 3;
}
elseif (@$newlogs_rest)
@@ -74,7 +74,7 @@
$tpl->cache_id = $exclude_country;
$logcount = 250;
$paging = false; // paging would have poor performance for all logs
$orderByDate = $logselection == 3 ? "{fromtable}.`date` DESC, " : "";
$orderByDate = $logselection == 3 ? "{fromtable}.`order_date` DESC, " : "";
}
else
{
@@ -96,7 +96,7 @@
$tpl->cache_id = $country;
$logcount = 250;
$paging = false; // paging would have poor performance for all logs
$orderByDate = $logselection == 3 ? "{fromtable}.`date` DESC, " : "";
$orderByDate = $logselection == 3 ? "{fromtable}.`order_date` DESC, " : "";
$optimize_for_latest_logs = ($country == '' || $country == $opt['page']['main_country']);
}
@@ -126,7 +126,7 @@
CREATE TEMPORARY TABLE &loglist0
(SELECT
`id`, `cache_id`, `user_id`, `date_created`, `date`, `type`,
`needs_maintenance`, `listing_outdated`
`needs_maintenance`, `listing_outdated`, `order_date`
FROM `cache_logs`
ORDER BY `date_created` DESC
LIMIT " . (4*$logcount) . "

0 comments on commit fb18fe0

Please sign in to comment.
You can’t perform that action at this time.