Skip to content

Commit

Permalink
try to increase performance for json file delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
aiomaster committed Feb 15, 2013
1 parent 8b368de commit fae5b4d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
7 changes: 4 additions & 3 deletions server/class.Wiwosm.php
Expand Up @@ -718,15 +718,16 @@ function createlinks($lang, $article, $geojson, $lang_hstore = '', $forceIWLLupd
if ($neednoIWLLupdate) return true;

// get the relativ filepath
$filepath = $this->getFilePath($lang,$article,true);
//$langarray = $this->queryInterWikiLanguages($lang,$article);
// $filepath = $this->getFilePath($lang,$article,true);

$langarray = self::hstoreToArray($lang_hstore);
// for every interwikilink do a hard link to the real file written above
foreach ($langarray as $l => $a) {
if ($l != $lang) {
$linkpath = $this->getFilePath($l,$a);
@unlink($linkpath);
symlink('../../'.$filepath,$linkpath);
//symlink('../../'.$filepath,$linkpath);
link($filepath,$linkpath);
unset($linkpath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/gen_json_files.php
Expand Up @@ -30,7 +30,7 @@
echo 'skip DB Update - doing linkupdate only'."\n";
}
$wiwosm->processOsmItems();
if ($fullupdate) $wiwosm->testAndRename();
if ($fullupdate || $linkupdate) $wiwosm->testAndRename();
$wiwosm->exithandler();
}

Expand Down
45 changes: 39 additions & 6 deletions server/public_html/osmjson/getGeoJSON.php
Expand Up @@ -5,33 +5,66 @@

header('Access-Control-Allow-Origin: *');

require('/home/master/class.Wiwosm.php');
// TODO: Refactor the filepath functions here and in class.Wiwosm.php

define('JSON_PATH','/mnt/user-store/wiwosm/geojsongz');

/**
* fnvhash funtion copied from http://code.google.com/p/boyanov/wiki/FNVHash
* @param string $txt Input text to hash
* @return string FNVHash of text
**/
function fnvhash($txt) {
$buf = str_split($txt);
$hash = 16777619;
foreach ($buf as $chr)
{
$hash += ($hash << 1) + ($hash << 4) + ($hash << 7) + ($hash << 8) + ($hash << 24);
$hash = $hash ^ ord($chr);
}
$hash = $hash & 0x0ffffffff;
return sprintf("%X", $hash);
}

/**
* This function computes a filepath for a given lang/article combination
* so that a good distributed tree will result in the filesystem.
* @param string $lang the language of the given article
* @param string $article the name of the article
* @return string the absolute filepath for this lang and article
**/
function getFilePath($lang, $article) {
$article = str_replace('_',' ',$article);
$hash = fnvhash($lang.$article);
return JSON_PATH . '/'.substr($hash,0,2).'/'.substr($hash,0,4).'/'.$hash.'_'.substr(str_replace(array("\0",'/'),array('','-'),$lang.'_'.$article),0,230).'.geojson.gz';
}



$article = $_GET['article'];
$lang = $_GET['lang'];

$wiwosm = new Wiwosm();

// status check for multiple, comma-separated articles
if ($_GET['action'] == 'check' && $lang && $_REQUEST['articles']) {
header('Content-Encoding: text/plain');
$articles = explode(',', $_REQUEST['articles']);
foreach ($articles as $article) {
$file = $wiwosm->getFilePath($lang, $article);
$file = getFilePath($lang, $article);
print "$article\t" . (file_exists($file) ? 1 : 0) . "\n";
}
exit();
}

if ($_GET['action']=='purge' && $article && $lang) {

require('/home/master/class.Wiwosm.php');
$wiwosm = new Wiwosm();
// no output please
ob_start();
$wiwosm->updateOneObject($lang,$article);
ob_end_clean();
}

$file = $wiwosm->getFilePath($lang,$article);
$file = getFilePath($lang,$article);
if (file_exists($file)) {
if ($_GET['action']=='check') {
echo 1;
Expand Down
2 changes: 1 addition & 1 deletion server/wiwosm.sh
Expand Up @@ -10,7 +10,7 @@
#$ -e $HOME/log/wiwosm.err


if [ `date +%u` -eq 3 ]
if test `date +%u` -eq 3
then
php /home/master/gen_json_files.php full
else
Expand Down

0 comments on commit fae5b4d

Please sign in to comment.