1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Move values the mainmenu caches to dedicated files (#14433)

This commit is contained in:
sfan5 2024-03-30 11:06:28 +01:00 committed by GitHub
parent bb6782ca58
commit 6c6e48f006
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 142 additions and 132 deletions

View file

@ -26,13 +26,23 @@ if not core.get_http_api then
end
assert(core.create_dir(core.get_cache_path() .. DIR_DELIM .. "cdb"))
local cache_file_path = core.get_cache_path() .. DIR_DELIM .. "cdb" .. DIR_DELIM .. "updates.json"
local has_fetched = false
local latest_releases
do
local tmp = core.get_once("cdb_latest_releases")
if tmp then
latest_releases = core.deserialize(tmp, true)
has_fetched = latest_releases ~= nil
if check_cache_age("cdb_updates_last_checked", 3 * 3600) then
local f = io.open(cache_file_path, "r")
local data = ""
if f then
data = f:read("*a")
f:close()
end
data = data ~= "" and core.parse_json(data) or nil
if type(data) == "table" then
latest_releases = data
has_fetched = true
end
end
end
@ -97,7 +107,8 @@ local function fetch()
return
end
latest_releases = lowercase_keys(releases)
core.set_once("cdb_latest_releases", core.serialize(latest_releases))
core.safe_file_write(cache_file_path, core.write_json(latest_releases))
cache_settings:set("cdb_updates_last_checked", tostring(os.time()))
if update_detector.get_count() > 0 then
local maintab = ui.find_by_name("maintab")