Save towns as plain PHP File in cache folder

+ Also load them on install + on reload items
= better performance when in dev mode
This commit is contained in:
slawkens
2020-10-09 22:27:48 +02:00
parent 3090989dea
commit ab3912b378
6 changed files with 155 additions and 57 deletions

View File

@@ -159,60 +159,5 @@ else {
}
unset($tmp, $id, $vocation);
//////////////////////////////////////
// load towns from database or OTBM //
//////////////////////////////////////
$tmp = '';
$towns = [];
if($cache->enabled() && $cache->fetch('towns', $tmp)) {
$towns = unserialize($tmp);
}
else {
if($db->hasTable('towns')) {
$query = $db->query('SELECT `id`, `name` FROM `towns`;')->fetchAll(PDO::FETCH_ASSOC);
foreach($query as $town) {
$towns[$town['id']] = $town['name'];
}
unset($query);
}
else {
$mapName = configLua('mapName');
if (!isset($mapName)) {
$mapName = configLua('map');
$mapFile = $config['server_path'] . $mapName;
}
if (strpos($mapName, '.otbm') === false) {
$mapName .= '.otbm';
}
if (!isset($mapFile)) {
$mapFile = config('data_path') . 'world/' . $mapName;
}
if (file_exists($mapFile)) {
ini_set('memory_limit', '-1');
require LIBS . 'TownsReader.php';
$townsReader = new TownsReader($mapFile);
$townsReader->load();
$towns = $townsReader->get();
}
else {
$towns = config('towns');
}
}
if($cache->enabled()) {
$cache->set('towns', serialize($towns), 600);
}
}
config(['towns', $towns]);
////////////////////////////////////////////
// END - load towns from database or OTBM //
////////////////////////////////////////////
require LIBS . 'Towns.php';
Towns::load();