From 0b1bd44d2228ba3a55500c023a5bd49904033ab2 Mon Sep 17 00:00:00 2001 From: Ferywir <65760459+Ferywir@users.noreply.github.com> Date: Tue, 16 Jun 2026 17:22:10 +0200 Subject: [PATCH] Perf: cache zero building levels in getFieldLevelInVillage [#155] (#235) --- GameEngine/Database.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GameEngine/Database.php b/GameEngine/Database.php index fd9edc8e..9a300206 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -3729,9 +3729,12 @@ class MYSQLi_DB implements IDbConnection { $vid = (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::$fieldLevelsInVillageSearchCache, $vid.$fieldType)) && !is_null($cachedValue)) { - return $cachedValue; + // required is already cached. NB: use isset() rather than the generic + // returnCachedContent(), which treats a cached level of 0 as "empty" and + // re-queries it on every call — buildings the village does not own + // (level 0, very common) would otherwise never be cached. + if ($use_cache && isset(self::$fieldLevelsInVillageSearchCache[$vid.$fieldType])) { + return self::$fieldLevelsInVillageSearchCache[$vid.$fieldType]; } // $fieldType can be both, integer and string, to be used in the IN statement,