Exemplo n.º 1
0
 public function cleanup_slave($slaveId)
 {
     // ensure old slave is disconnected
     sql_disconnect_slave();
     // connect the slave
     if ($slaveId == -1) {
         sql_connect_master_as_slave();
     } else {
         sql_connect_slave($slaveId);
     }
     $this->cleanup_mapresult2($slaveId);
     // disconnect slave
     sql_disconnect_slave();
 }
Exemplo n.º 2
0
function sql_connect_anyslave()
{
    global $db, $opt, $login;
    if ($db['dblink_slave'] !== false) {
        return;
    }
    $nMaxTimeDiff = $opt['db']['slave']['max_behind'];
    if ($login->userid != 0) {
        $nMaxTimeDiff = sql_value("SELECT TIMESTAMP(NOW())-TIMESTAMP(`datExclude`)\n            FROM `sys_repl_exclude`\n            WHERE `user_id`='&1'", $opt['db']['slave']['max_behind'], $login->userid);
        if ($nMaxTimeDiff > $opt['db']['slave']['max_behind']) {
            $nMaxTimeDiff = $opt['db']['slave']['max_behind'];
        }
    }
    $id = sqlf_value("SELECT `id`, `weight`*RAND() AS `w`\n        FROM `sys_repl_slaves`\n        WHERE `active`= 1 \n        AND `online`= 1 \n        AND (TIMESTAMP(NOW())-TIMESTAMP(`last_check`)+`time_diff`<'&1')\n        ORDER BY `w` DESC LIMIT 1", -1, $nMaxTimeDiff);
    sql_connect_slave($id);
}
Exemplo n.º 3
0
function output_searchresult($nResultId, $compact, $nLon1, $nLon2, $nLat1, $nLat2, $cachenames, $smallmap, $showlockedcaches)
{
    global $login, $opt, $useragent_msie;
    // check if data is available and connect the right slave server
    $nSlaveId = sql_value("SELECT `slave_id` FROM `map2_result` WHERE `result_id`='&1' AND DATE_ADD(`date_created`, INTERVAL '&2' SECOND)>NOW()", -2, $nResultId, $opt['map']['maxcacheage']);
    if ($nSlaveId == -2) {
        echo '<searchresult count="0" available="0">';
        echo '</searchresult>';
        exit;
    }
    sql_connect_slave($nSlaveId);
    sql("UPDATE `map2_result` SET `request_counter`=`request_counter`+1, `date_lastqueried`=NOW() WHERE `result_id`='&1'", $nResultId);
    // execute query and return search result
    $nRecordCount = sql_value_slave("SELECT COUNT(*) FROM `map2_data` INNER JOIN `caches` ON `map2_data`.`cache_id`=`caches`.`cache_id` WHERE `map2_data`.`result_id`='&1' AND `caches`.`longitude`>'&2' AND `caches`.`longitude`<'&3' AND `caches`.`latitude`>'&4' AND `caches`.`latitude`<'&5'", 0, $nResultId, $nLon1, $nLon2, $nLat1, $nLat2);
    // TODO: SQL_CALC_FOUND_ROWS + $nRecordCount = sql_value_slave("SELECT FOUND_ROWS()", 0);
    // determine max. number of records to send
    $maxrecords = $opt['map']['maxrecords'] + 0;
    if ($login->userid > 0) {
        $user_maxrecords = sql_value("SELECT option_value FROM user_options WHERE user_id='&1' AND option_id=8", $opt['map']['maxrecords'] + 0, $login->userid);
        if ($user_maxrecords > 0 && (!$useragent_msie || $user_maxrecords < $maxrecords)) {
            $maxrecords = min(max($user_maxrecords, $opt['map']['min_maxrecords']), $opt['map']['max_maxrecords']);
        }
    } else {
        $user_maxrecords = 0;
    }
    if ($smallmap && $user_maxrecords == 0 && $maxrecords > 1000) {
        $maxrecords = floor($maxrecords * 0.65);
    }
    $bMaxRecordReached = $nRecordCount > $maxrecords;
    // output data
    echo '<searchresult count="' . xmlentities($nRecordCount) . '" available="1"' . ' maxrecordreached="' . ($bMaxRecordReached ? '1' : '0') . '">' . "\n";
    if (!$bMaxRecordReached) {
        $namequery = $cachenames ? ", `caches`.`name` AS `cachename`" : "";
        $rs = sql_slave("SELECT SQL_BUFFER_RESULT \n                            distinct `caches`.`wp_oc`,\n                            `caches`.`longitude`, `caches`.`latitude`,\n                            `caches`.`type`, \n                            `caches`.`status`>1 AS `inactive`,\n                            `caches`.`type`=6 AND `caches`.`date_hidden`+INTERVAL 1 DAY < NOW() AS `oldevent`,\n                            `user`.`user_id`='&6' AS `owned`,\n                            IF(`found_logs`.`id` IS NULL, 0, 1) AS `found`,\n                            IF(`found_logs`.`id` IS NULL AND `notfound_logs`.`id` IS NOT NULL, 1, 0) AS `notfound`,\n                            IF(`caches_attributes`.`attrib_id` IS NULL, 0, 1) AS `oconly`" . $namequery . "\n                       FROM `map2_data`\n                 INNER JOIN `caches` ON `map2_data`.`cache_id`=`caches`.`cache_id`\n                 INNER JOIN `user` ON `user`.`user_id`=`caches`.`user_id`\n                  LEFT JOIN `cache_logs` `found_logs` ON `found_logs`.`cache_id`=`caches`.`cache_id` AND `found_logs`.`user_id`='&6' AND `found_logs`.`type` IN (1,7)\n                  LEFT JOIN `cache_logs` `notfound_logs` ON `notfound_logs`.`cache_id`=`caches`.`cache_id` AND `notfound_logs`.`user_id`='&6' AND `notfound_logs`.`type`=2\n                  LEFT JOIN `caches_attributes` ON `caches_attributes`.`cache_id`=`caches`.`cache_id` AND `caches_attributes`.`attrib_id`=6\n                      WHERE `map2_data`.`result_id`='&1' AND `caches`.`longitude`>'&2' AND `caches`.`longitude`<'&3' AND `caches`.`latitude`>'&4' AND `caches`.`latitude`<'&5'\n\t                      AND (`caches`.`status`<>5 OR `caches`.`user_id`='&6')   /* hide unpublished caches */\n\t                      AND `caches`.`status`<>'&7' /* ... and vandalized listings, locked duplicates etc. */\n\t                      AND `caches`.`status`<>7    /* ... and locked/invisible caches */\n\t\t\t\t\t\t\t\t\t ORDER BY `caches`.`status` DESC, `oconly` AND NOT (`found` OR `notfound`), NOT (`found` OR `notfound`), `caches`.`type`<>4, MD5(`caches`.`name`)\n\t\t\t\t\t\t\t\t\t LIMIT &8", $nResultId, $nLon1, $nLon2, $nLat1, $nLat2, $login->userid, $showlockedcaches ? 0 : 6, $maxrecords);
        while ($r = sql_fetch_assoc($rs)) {
            $flags = 0;
            if ($r['owned']) {
                $flags |= 1;
            }
            if ($r['found']) {
                $flags |= 2;
            }
            if ($r['notfound']) {
                $flags |= 4;
            }
            if ($r['inactive'] || $r['oldevent']) {
                $flags |= 8;
            }
            if ($r['oconly']) {
                $flags |= 16;
            }
            if ($compact) {
                echo '<c d="' . xmlentities($r['wp_oc'] . '/' . round($r['longitude'], 5) . '/' . round($r['latitude'], 5) . '/' . $r['type'] . '/' . $flags) . '"' . (isset($r['cachename']) ? ' n="' . xmlentities($r['cachename']) . '"' : '') . ' />';
            } else {
                echo '<cache wp="' . xmlentities($r['wp_oc']) . '"' . ' lon="' . xmlentities(round($r['longitude'], 5)) . '"' . ' lat="' . xmlentities(round($r['latitude'], 5)) . '"' . ' type="' . xmlentities($r['type']) . '"' . (isset($r['cachename']) ? ' n="' . xmlentities($r['cachename']) . '"' : '') . ' f="' . xmlentities($flags) . '" />' . "\n";
            }
        }
        sql_free_result($rs);
    }
    echo '</searchresult>';
    exit;
}
Exemplo n.º 4
0
function output_searchresult($nResultId, $nLon1, $nLat1, $nLon2, $nLat2)
{
    global $opt;
    // check if data is available and connect the right slave server
    $nSlaveId = sql_value("SELECT `slave_id` FROM `map2_result` WHERE `result_id`='&1' AND DATE_ADD(`date_created`, INTERVAL '&2' SECOND)>NOW()", -2, $nResultId, $opt['map']['maxcacheage']);
    if ($nSlaveId == -2) {
        echo '<searchresult count="0" available="0">';
        echo '</searchresult>';
        exit;
    }
    sql_connect_slave($nSlaveId);
    sql("UPDATE `map2_result` SET `request_counter`=`request_counter`+1, `date_lastqueried`=NOW() WHERE `result_id`='&1'", $nResultId);
    // execute query and return search result
    $nRecordCount = sql_value_slave("SELECT COUNT(*) FROM `map2_data` INNER JOIN `caches` ON `map2_data`.`cache_id`=`caches`.`cache_id` WHERE `map2_data`.`result_id`='&1' AND `caches`.`longitude`>'&2' AND `caches`.`longitude`<'&3' AND `caches`.`latitude`>'&4' AND `caches`.`latitude`<'&5'", 0, $nResultId, $nLon1, $nLon2, $nLat1, $nLat2);
    // TODO: SQL_CALC_FOUND_ROWS + $nRecordCount = sql_value_slave("SELECT FOUND_ROWS()", 0);
    $bMaxRecordReached = false;
    if ($nRecordCount > $opt['map']['maxrecords']) {
        $bMaxRecordReached = true;
    }
    echo '<searchresult count="' . $nRecordCount . '" available="1" maxrecordreached="' . ($bMaxRecordReached ? '1' : '0') . '">' . "\n";
    if ($bMaxRecordReached == false) {
        $rs = sql_slave("SELECT SQL_BUFFER_RESULT `caches`.`wp_oc`, `caches`.`longitude`, `caches`.`latitude`, `caches`.`type` FROM `map2_data` INNER JOIN `caches` ON `map2_data`.`cache_id`=`caches`.`cache_id` WHERE `map2_data`.`result_id`='&1' AND `caches`.`longitude`>'&2' AND `caches`.`longitude`<'&3' AND `caches`.`latitude`>'&4' AND `caches`.`latitude`<'&5' LIMIT " . ($opt['map']['maxrecords'] + 0), $nResultId, $nLon1, $nLon2, $nLat1, $nLat2);
        while ($r = sql_fetch_assoc($rs)) {
            echo '<cache wp="' . xmlentities($r['wp_oc']) . '" lon="' . xmlentities($r['longitude']) . '" lat="' . xmlentities($r['latitude']) . '" type="' . xmlentities($r['type']) . '" />' . "\n";
        }
        sql_free_result($rs);
    }
    echo '</searchresult>';
    exit;
}