fix caching for userconfigs

This commit is contained in:
Shish 2023-02-02 16:39:36 +00:00
parent 708e102338
commit 5ef6268e54

View file

@ -277,13 +277,9 @@ class DatabaseConfig extends BaseConfig
$this->table_name = $table_name; $this->table_name = $table_name;
$this->sub_value = $sub_value; $this->sub_value = $sub_value;
$this->sub_column = $sub_column; $this->sub_column = $sub_column;
$this->cache_name = empty($sub_value) ? "config" : "config_{$sub_value}";
$cache_name = "config"; $cached = $cache->get($this->cache_name);
if (!empty($sub_value)) {
$cache_name .= "_".$sub_value;
}
$cached = $cache->get($cache_name);
if (!is_null($cached)) { if (!is_null($cached)) {
$this->values = $cached; $this->values = $cached;
} else { } else {
@ -300,7 +296,7 @@ class DatabaseConfig extends BaseConfig
foreach ($this->database->get_all($query, $args) as $row) { foreach ($this->database->get_all($query, $args) as $row) {
$this->values[$row["name"]] = $row["value"]; $this->values[$row["name"]] = $row["value"];
} }
$cache->set($cache_name, $this->values); $cache->set($this->cache_name, $this->values);
} }
} }
@ -335,7 +331,7 @@ class DatabaseConfig extends BaseConfig
} }
// rather than deleting and having some other request(s) do a thundering // rather than deleting and having some other request(s) do a thundering
// herd of race-conditioned updates, just save the updated version once here // herd of race-conditioned updates, just save the updated version once here
$cache->set("config", $this->values); $cache->set($this->cache_name, $this->values);
$this->database->notify("config"); $this->database->notify($this->cache_name);
} }
} }