fix(init): persist compiled database metadata in cache
This commit is contained in:
+16
-10
@@ -30,6 +30,10 @@ local function safeYield()
|
||||
end
|
||||
end
|
||||
|
||||
local function GetCompiledDBMetadataBucket()
|
||||
return Questie.dbCache and Questie.dbCache.global or Questie.db.global
|
||||
end
|
||||
|
||||
---@alias CompilerTypes
|
||||
---| "u8"
|
||||
---| "u16"
|
||||
@@ -1096,19 +1100,21 @@ function QuestieDBCompiler:Compile()
|
||||
QuestieDBCompiler:CompileItems()
|
||||
print("\124cFFAAEEFF"..l10n("Questie DB update complete!"))
|
||||
|
||||
Questie.db.global.dbCompiledExpansion = WOW_PROJECT_ID
|
||||
Questie.db.global.dbCompiledPluginSignature = QuestiePluginAPI:GetLoadedSignature()
|
||||
local metadataBucket = GetCompiledDBMetadataBucket()
|
||||
metadataBucket.dbCompiledExpansion = WOW_PROJECT_ID
|
||||
metadataBucket.dbCompiledPluginSignature = QuestiePluginAPI:GetLoadedSignature()
|
||||
|
||||
if Questie.IsSoD then
|
||||
Questie.db.global.sod.dbCompiledOnVersion = QuestieLib:GetAddonVersionString()
|
||||
Questie.db.global.sod.dbCompiledLang = l10n:GetUILocale()
|
||||
Questie.db.global.sod.dbIsCompiled = true
|
||||
Questie.db.global.sod.dbCompiledCount = (Questie.db.global.sod.dbCompiledCount or 0) + 1
|
||||
metadataBucket.sod = metadataBucket.sod or {}
|
||||
metadataBucket.sod.dbCompiledOnVersion = QuestieLib:GetAddonVersionString()
|
||||
metadataBucket.sod.dbCompiledLang = l10n:GetUILocale()
|
||||
metadataBucket.sod.dbIsCompiled = true
|
||||
metadataBucket.sod.dbCompiledCount = (metadataBucket.sod.dbCompiledCount or 0) + 1
|
||||
else
|
||||
Questie.db.global.dbCompiledOnVersion = QuestieLib:GetAddonVersionString()
|
||||
Questie.db.global.dbCompiledLang = l10n:GetUILocale()
|
||||
Questie.db.global.dbIsCompiled = true
|
||||
Questie.db.global.dbCompiledCount = (Questie.db.global.dbCompiledCount or 0) + 1
|
||||
metadataBucket.dbCompiledOnVersion = QuestieLib:GetAddonVersionString()
|
||||
metadataBucket.dbCompiledLang = l10n:GetUILocale()
|
||||
metadataBucket.dbIsCompiled = true
|
||||
metadataBucket.dbCompiledCount = (metadataBucket.dbCompiledCount or 0) + 1
|
||||
end
|
||||
|
||||
QuestieDBCompiler._isCompiling = false
|
||||
|
||||
@@ -97,7 +97,7 @@ local migrationFunctions = {
|
||||
end
|
||||
end
|
||||
-- Move global metadata
|
||||
local globalMetadata = {"dbCompiledExpansion", "dbCompiledOnVersion", "dbCompiledLang", "dbIsCompiled", "dbCompiledCount"}
|
||||
local globalMetadata = {"dbCompiledExpansion", "dbCompiledPluginSignature", "dbCompiledOnVersion", "dbCompiledLang", "dbIsCompiled", "dbCompiledCount"}
|
||||
for _, k in ipairs(globalMetadata) do
|
||||
if Questie.db.global[k] then
|
||||
Questie.dbCache.global[k] = Questie.db.global[k]
|
||||
|
||||
+26
-21
@@ -109,6 +109,19 @@ local function coYield()
|
||||
end
|
||||
end
|
||||
|
||||
local function GetCompiledDBMetadataBucket()
|
||||
return Questie.dbCache and Questie.dbCache.global or Questie.db.global
|
||||
end
|
||||
|
||||
local function GetCompiledDBMetadata()
|
||||
local bucket = GetCompiledDBMetadataBucket()
|
||||
if Questie.IsSoD then
|
||||
bucket.sod = bucket.sod or {}
|
||||
return bucket.sod, bucket
|
||||
end
|
||||
return bucket, bucket
|
||||
end
|
||||
|
||||
local function _dbStats(t)
|
||||
if type(t) ~= "table" then return "type=" .. type(t) end
|
||||
local n, minK, maxK = 0, math.huge, 0
|
||||
@@ -259,16 +272,10 @@ QuestieInit.Stages[1] = function() -- run as a coroutine
|
||||
|
||||
local dbCompiled = false
|
||||
|
||||
local dbIsCompiled, dbCompiledOnVersion, dbCompiledLang
|
||||
if Questie.IsSoD then
|
||||
dbIsCompiled = Questie.db.global.sod.dbIsCompiled or false
|
||||
dbCompiledOnVersion = Questie.db.global.sod.dbCompiledOnVersion
|
||||
dbCompiledLang = Questie.db.global.sod.dbCompiledLang
|
||||
else
|
||||
dbIsCompiled = Questie.db.global.dbIsCompiled or false
|
||||
dbCompiledOnVersion = Questie.db.global.dbCompiledOnVersion
|
||||
dbCompiledLang = Questie.db.global.dbCompiledLang
|
||||
end
|
||||
local compiledMetadata, compiledRootMetadata = GetCompiledDBMetadata()
|
||||
local dbIsCompiled = compiledMetadata.dbIsCompiled or false
|
||||
local dbCompiledOnVersion = compiledMetadata.dbCompiledOnVersion
|
||||
local dbCompiledLang = compiledMetadata.dbCompiledLang
|
||||
|
||||
|
||||
if Questie.IsSoD then
|
||||
@@ -277,11 +284,7 @@ QuestieInit.Stages[1] = function() -- run as a coroutine
|
||||
end
|
||||
|
||||
-- Check if the DB needs to be recompiled
|
||||
local dbCompiledOnVersion = Questie.db.global.dbCompiledOnVersion
|
||||
local dbCompiledLang = Questie.db.global.dbCompiledLang
|
||||
local dbIsCompiled = Questie.db.global.dbIsCompiled
|
||||
|
||||
needsCompilation = (not dbIsCompiled) or (QuestieLib:GetAddonVersionString() ~= dbCompiledOnVersion) or (l10n:GetUILocale() ~= dbCompiledLang) or (Questie.db.global.dbCompiledExpansion ~= WOW_PROJECT_ID)
|
||||
needsCompilation = (not dbIsCompiled) or (QuestieLib:GetAddonVersionString() ~= dbCompiledOnVersion) or (l10n:GetUILocale() ~= dbCompiledLang) or (compiledRootMetadata.dbCompiledExpansion ~= WOW_PROJECT_ID)
|
||||
|
||||
-- Custom servers or presence of DB plugins: always defer to Stage3 to wait for plugin data injection
|
||||
if Questie.IsAscension or Questie.IsEbonhold or Questie.IsValanior or QuestieServer:IsAnyDBPluginEnabled() then
|
||||
@@ -307,7 +310,7 @@ QuestieInit.Stages[1] = function() -- run as a coroutine
|
||||
QuestieCorrections:MinimalInit()
|
||||
end
|
||||
|
||||
local dbCompiledCount = Questie.IsSoD and Questie.db.global.sod.dbCompiledCount or Questie.db.global.dbCompiledCount
|
||||
local dbCompiledCount = compiledMetadata.dbCompiledCount
|
||||
|
||||
if (not Questie.db.char.townsfolk) or (dbCompiledCount ~= Questie.db.char.townsfolkVersion) or (Questie.db.char.townsfolkClass ~= UnitClass("player")) then
|
||||
Questie.db.char.townsfolkVersion = dbCompiledCount
|
||||
@@ -404,11 +407,13 @@ QuestieInit.Stages[3] = function() -- run as a coroutine
|
||||
-- does not require rebuilding the binary DB cache on every login.
|
||||
local isCustomServer = Questie.IsAscension or Questie.IsEbonhold or Questie.IsValanior or QuestieServer:IsAnyDBPluginEnabled()
|
||||
local pluginSignature = QuestiePluginAPI:GetLoadedSignature()
|
||||
local cacheMatchesPlugins = Questie.db.global.dbCompiledPluginSignature == pluginSignature
|
||||
local cacheMatchesCore = Questie.db.global.dbIsCompiled
|
||||
and (QuestieLib:GetAddonVersionString() == Questie.db.global.dbCompiledOnVersion)
|
||||
and (l10n:GetUILocale() == Questie.db.global.dbCompiledLang)
|
||||
and (Questie.db.global.dbCompiledExpansion == WOW_PROJECT_ID)
|
||||
local stage3CompiledMetadata, stage3CompiledRootMetadata = GetCompiledDBMetadata()
|
||||
local cacheMatchesPlugins = stage3CompiledRootMetadata.dbCompiledPluginSignature == pluginSignature
|
||||
or (Questie.db.global and Questie.db.global.dbCompiledPluginSignature == pluginSignature)
|
||||
local cacheMatchesCore = stage3CompiledMetadata.dbIsCompiled
|
||||
and (QuestieLib:GetAddonVersionString() == stage3CompiledMetadata.dbCompiledOnVersion)
|
||||
and (l10n:GetUILocale() == stage3CompiledMetadata.dbCompiledLang)
|
||||
and (stage3CompiledRootMetadata.dbCompiledExpansion == WOW_PROJECT_ID)
|
||||
|
||||
if needsCompilation or (not cacheMatchesCore) or (isCustomServer and (not cacheMatchesPlugins)) then
|
||||
Questie:Debug(Questie.DEBUG_CRITICAL, "[QuestieInit:Stage3] Starting compilation (Server=" .. tostring(isCustomServer) .. ", Needed=" .. tostring(needsCompilation) .. ")")
|
||||
|
||||
Reference in New Issue
Block a user