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