4071/4179: fixed waypoint generation
- removed 4-hexdigit-limit (OCFFFF) - improved hack for WP-generation race conditions
This commit is contained in:
@ -15,3 +15,5 @@ date commit ID change
|
||||
- change cache_logs.last_modified and cache_logs_archived.last_modified
|
||||
field type from 'datetime' to 'timestamp'
|
||||
See installation instructions at http://code.google.com/p/opencaching-api
|
||||
|
||||
2012-08-23 increased caches.wp_oc length from 6 to 7 chars
|
||||
|
@ -23,7 +23,7 @@ CREATE TABLE `caches` (
|
||||
`way_length` float unsigned NOT NULL default '0',
|
||||
`wp_gc` varchar(7) NOT NULL,
|
||||
`wp_nc` varchar(6) NOT NULL,
|
||||
`wp_oc` varchar(6) default NULL,
|
||||
`wp_oc` varchar(7) default NULL,
|
||||
`desc_languages` varchar(60) NOT NULL COMMENT 'via Trigger (cache_desc)',
|
||||
`default_desclang` char(2) NOT NULL,
|
||||
`date_activate` datetime default NULL,
|
||||
|
@ -88,34 +88,40 @@
|
||||
{
|
||||
global $oc_waypoint_prefix;
|
||||
|
||||
$bLoop = true;
|
||||
// The following code runs into trouble, if multiple users/threads request a new
|
||||
// waypoint synchronously (-> RT ticket #4071). We will hack around this problem by
|
||||
// repeating the operation with random delays. Another solution would be a table-lock.
|
||||
|
||||
// falls mal was nicht so funktioniert wie es soll ...
|
||||
$nMaxLoop = 10;
|
||||
$nLoop = 0;
|
||||
// 2012-08-23 following
|
||||
// changes: removed 4 hexdigits limit; added random delay;
|
||||
// increased maxloop 10 -> 20; simplified loop
|
||||
|
||||
while (($bLoop == true) && ($nLoop < $nMaxLoop))
|
||||
$nLoop = 20;
|
||||
|
||||
do
|
||||
{
|
||||
$rs = sql("SELECT MAX(`wp_oc`) `maxwp` FROM `caches` WHERE wp_oc!='OCGC77'");
|
||||
// add zero to convert CONV's string result to a sortable number
|
||||
$rs = sql("SELECT MAX(0 + CONV(SUBSTR(wp_oc,3),16,10)) maxwp FROM `caches` WHERE wp_oc!='OCGC77'");
|
||||
$r = sql_fetch_assoc($rs);
|
||||
mysql_free_result($rs);
|
||||
|
||||
if ($r['maxwp'] == null)
|
||||
$nNext = 1;
|
||||
$nNext = 1; // first cache in database
|
||||
else
|
||||
$nNext = hexdec(mb_substr($r['maxwp'], 2, 4)) + 1;
|
||||
$nNext = $r['maxwp'] + 1;
|
||||
|
||||
$nNext = dechex($nNext);
|
||||
|
||||
while (mb_strlen($nNext) < 4)
|
||||
$nNext = '0' . $nNext;
|
||||
|
||||
$sWP = $oc_waypoint_prefix . mb_strtoupper($nNext);
|
||||
|
||||
$bLoop = false;
|
||||
$nLoop++;
|
||||
sql("UPDATE IGNORE `caches` SET `wp_oc`='&1' WHERE `cache_id`='&2' AND ISNULL(`wp_oc`)", $sWP, $cacheid) || $bLoop = true;
|
||||
}
|
||||
if (sql("UPDATE IGNORE `caches` SET `wp_oc`='&1' WHERE `cache_id`='&2' AND ISNULL(`wp_oc`)", $sWP, $cacheid))
|
||||
$nLoop = 0;
|
||||
else
|
||||
usleep(rand(0,50000));
|
||||
|
||||
} while (--$nLoop > 0);
|
||||
}
|
||||
|
||||
function setLastFound($cacheid)
|
||||
|
@ -30,7 +30,7 @@
|
||||
</form>
|
||||
<?php
|
||||
|
||||
$rsCaches = sql("SELECT DISTINCT `caches`.`wp_oc` FROM `caches` INNER JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id` INNER JOIN `user` ON `cache_logs`.`user_id`=`user`.`user_id` WHERE `caches`.`status` IN (1,2) AND `cache_logs`.`type`=3 AND `user`.`username`='&1' ORDER BY `cache_logs`.`date` DESC, `caches`.`wp_oc`", $sUser);
|
||||
$rsCaches = sql("SELECT DISTINCT `caches`.`wp_oc` FROM `caches` INNER JOIN `cache_logs` ON `caches`.`cache_id`=`cache_logs`.`cache_id` INNER JOIN `user` ON `cache_logs`.`user_id`=`user`.`user_id` WHERE `caches`.`status` IN (1,2) AND `cache_logs`.`type`=3 AND `user`.`username`='&1' ORDER BY `cache_logs`.`date` DESC, `caches`.`cache_id`", $sUser);
|
||||
while ($rCache = sql_fetch_assoc($rsCaches))
|
||||
{
|
||||
echo '<a href="javascript:select(\'' . $rCache['wp_oc'] . '\')">' . $rCache['wp_oc'] . '<br />';
|
||||
|
Reference in New Issue
Block a user