diff --git a/cachers.php b/cachers.php
index ffc9db1..af40ecc 100644
--- a/cachers.php
+++ b/cachers.php
@@ -666,49 +666,13 @@ function cacheStatusModules() : void
}
-function cacheStatusCount() : void
+function cacheGameCount() : void
{
- $db = getDatabase();
-
- $a_cache = array();
-
- // Fetch general count per status
- $q_status = mysqli_query($db, "SELECT `status`+0 AS `sid`, count(*) AS `c`
- FROM `game_list`
- WHERE `network` = 0
- OR (`network` = 1 && `status` <= 2)
- GROUP BY `status`;");
-
- mysqli_close($db);
-
- if (is_bool($q_status))
- return;
-
- $a_cache[0][0] = 0;
-
- while ($row = mysqli_fetch_object($q_status))
- {
- // This should be unreachable unless the database structure is damaged
- if (!property_exists($row, "sid") ||
- !property_exists($row, "c"))
- {
- return;
- }
-
- $a_cache[0][$row->sid] = (int) $row->c;
- $a_cache[0][0] += (int) $row->c;
- }
-
- $a_cache[1] = $a_cache[0];
-
- $f_count = fopen(__DIR__.'/cache/a_count.json', 'w');
- $json_data = json_encode($a_cache);
-
- if (!$f_count || !$json_data)
- return;
+ // count_game_entry_all
+ file_put_contents(__DIR__.'/cache/count_game_entry_all.txt', (string) count_game_entry_all(true));
- fwrite($f_count, $json_data);
- fclose($f_count);
+ // count_game_id_all
+ file_put_contents(__DIR__.'/cache/count_game_id_all.txt', (string) count_game_id_all(true));
}
diff --git a/config.php b/config.php
index 732713e..13ed009 100644
--- a/config.php
+++ b/config.php
@@ -136,6 +136,10 @@
'title' => "Update Status Module",
'success' => "Forced update on status modules"
),
+ 'cacheGameCount' => array(
+ 'title' => "Update Game Count",
+ 'success' => "Forced update on game count"
+ ),
'cacheWikiIDs' => array(
'title' => "Update Wiki IDs Cache",
'success' => "Forced update on Wiki IDs cache"
diff --git a/functions.php b/functions.php
index 74841cb..69f30d8 100644
--- a/functions.php
+++ b/functions.php
@@ -407,8 +407,18 @@ function countGames(mysqli $db, string $query = "") : array
}
-function count_game_entry_all() : int
+function count_game_entry_all(bool $ignore_cache = false) : int
{
+ // If we don't ignore cache, try to retrieve the value from cache
+ if (!$ignore_cache)
+ {
+ $count = file_get_contents(__DIR__.'/cache/count_game_entry_all.txt');
+
+ // Return value from cache only if available
+ if ($count !== false)
+ return (int) $count;
+ }
+
$db = getDatabase();
$ret = 0;
@@ -437,8 +447,18 @@ function count_game_entry_all() : int
}
-function count_game_id_all() : int
+function count_game_id_all(bool $ignore_cache = false) : int
{
+ // If we don't ignore cache, try to retrieve the value from cache
+ if (!$ignore_cache)
+ {
+ $count = file_get_contents(__DIR__.'/cache/count_game_id_all.txt');
+
+ // Return value from cache only if available
+ if ($count !== false)
+ return (int) $count;
+ }
+
$db = getDatabase();
$ret = 0;
diff --git a/includes/inc.panel.php b/includes/inc.panel.php
index 6edcc61..dd02a03 100644
--- a/includes/inc.panel.php
+++ b/includes/inc.panel.php
@@ -622,6 +622,8 @@ function compatibilityUpdater() : void
cacheInitials();
// Recache status modules
cacheStatusModules();
+ // Recache game count
+ cacheGameCount();
}
else
{
@@ -810,6 +812,8 @@ function mergeGames() : void
// Recache status modules
cacheStatusModules();
+ // Recache game count
+ cacheGameCount();
echo "Games successfully merged!
";
}