mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
refactor: units DB values caching
This commit is contained in:
+18
-7
@@ -184,6 +184,11 @@ class MYSQLi_DB implements IDbConnection {
|
||||
*/
|
||||
$coordsCache = [],
|
||||
|
||||
/**
|
||||
* @var array Cache of units in a village.
|
||||
*/
|
||||
$unitsCache = [],
|
||||
|
||||
/**
|
||||
* @var array Cache of messages to be sent out to players,
|
||||
* so we can collect them and send them out together
|
||||
@@ -4588,24 +4593,30 @@ class MYSQLi_DB implements IDbConnection {
|
||||
return mysqli_query($this->dblink,$q);
|
||||
}
|
||||
|
||||
function getUnit($vid) {
|
||||
function getUnit($vid, $use_cache = true) {
|
||||
list($vid) = $this->escape_input((int) $vid);
|
||||
|
||||
// first of all, check if we should be using cache and whether the field
|
||||
// required is already cached
|
||||
if ($use_cache && ($cachedValue = self::returnCachedContent(self::$unitsCache, $vid)) && !is_null($cachedValue)) {
|
||||
return $cachedValue;
|
||||
}
|
||||
|
||||
$q = "SELECT * from " . TB_PREFIX . "units where vref = $vid";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
if (!empty($result)) {
|
||||
return mysqli_fetch_assoc($result);
|
||||
self::$unitsCache[$vid] = mysqli_fetch_assoc($result);
|
||||
} else {
|
||||
return NULL;
|
||||
self::$unitsCache[$vid] = null;
|
||||
}
|
||||
|
||||
return self::$unitsCache[$vid];
|
||||
}
|
||||
|
||||
function getUnitsNumber($vid) {
|
||||
function getUnitsNumber($vid, $use_cache = false) {
|
||||
list($vid) = $this->escape_input((int) $vid);
|
||||
|
||||
$q = "SELECT * from " . TB_PREFIX . "units where vref = $vid";
|
||||
$result = mysqli_query($this->dblink,$q);
|
||||
$dbarray = mysqli_fetch_assoc($result);
|
||||
$dbarray = $this->getUnit($vid);
|
||||
$totalunits = 0;
|
||||
$movingunits = $this->getVillageMovement($vid);
|
||||
for($i=1;$i<=50;$i++){
|
||||
|
||||
Reference in New Issue
Block a user