fix: clear quest completion cache on refresh
This commit is contained in:
@@ -720,9 +720,18 @@ end
|
|||||||
|
|
||||||
-- Returns a list of quests the character has completed in its lifetime.
|
-- Returns a list of quests the character has completed in its lifetime.
|
||||||
-- https://wowpedia.fandom.com/wiki/API_GetQuestsCompleted
|
-- https://wowpedia.fandom.com/wiki/API_GetQuestsCompleted
|
||||||
|
local function ClearQuestCompleteTable(tbl)
|
||||||
|
if type(tbl) ~= "table" then return end
|
||||||
|
for key in pairs(tbl) do
|
||||||
|
tbl[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function QuestieCompat.GetQuestsCompleted()
|
function QuestieCompat.GetQuestsCompleted()
|
||||||
if not Questie.db.char.complete then
|
if not Questie.db.char.complete then
|
||||||
Questie.db.char.complete = {}
|
Questie.db.char.complete = {}
|
||||||
|
else
|
||||||
|
ClearQuestCompleteTable(Questie.db.char.complete)
|
||||||
end
|
end
|
||||||
|
|
||||||
QueryQuestsCompleted()
|
QueryQuestsCompleted()
|
||||||
@@ -732,6 +741,10 @@ end
|
|||||||
-- Fires when the data requested by QueryQuestsCompleted() is available.
|
-- Fires when the data requested by QueryQuestsCompleted() is available.
|
||||||
-- https://wowpedia.fandom.com/wiki/QUEST_QUERY_COMPLETE
|
-- https://wowpedia.fandom.com/wiki/QUEST_QUERY_COMPLETE
|
||||||
function QuestieCompat:QUEST_QUERY_COMPLETE(event)
|
function QuestieCompat:QUEST_QUERY_COMPLETE(event)
|
||||||
|
if not Questie.db.char.complete then
|
||||||
|
Questie.db.char.complete = {}
|
||||||
|
end
|
||||||
|
ClearQuestCompleteTable(Questie.db.char.complete)
|
||||||
GetQuestsCompleted(Questie.db.char.complete)
|
GetQuestsCompleted(Questie.db.char.complete)
|
||||||
|
|
||||||
local questId = next(Questie.db.char.complete)
|
local questId = next(Questie.db.char.complete)
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
local function read(path)
|
||||||
|
local f = assert(io.open(path, "r"), "cannot open " .. path)
|
||||||
|
local content = f:read("*a")
|
||||||
|
f:close()
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
|
||||||
|
describe("QuestieCompat completed quest refresh", function()
|
||||||
|
local compat = read("Compat/Compat.lua")
|
||||||
|
|
||||||
|
it("clears the completed-quest table before repopulating it", function()
|
||||||
|
local getQuestsStart = assert(compat:find("function QuestieCompat.GetQuestsCompleted()", 1, true))
|
||||||
|
local getQuestsEnd = assert(compat:find("-- Fires when the data requested by QueryQuestsCompleted() is available.", getQuestsStart, true))
|
||||||
|
local getQuests = compat:sub(getQuestsStart, getQuestsEnd)
|
||||||
|
|
||||||
|
local clearPos = assert(getQuests:find("ClearQuestCompleteTable(Questie.db.char.complete)", 1, true))
|
||||||
|
local queryPos = assert(getQuests:find("QueryQuestsCompleted()", 1, true))
|
||||||
|
assert.is_true(clearPos < queryPos)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("clears stale completions again when the server response arrives", function()
|
||||||
|
local eventStart = assert(compat:find("function QuestieCompat:QUEST_QUERY_COMPLETE(event)", 1, true))
|
||||||
|
local eventEnd = assert(compat:find("-- https://wowpedia.fandom.com/wiki/API_IsQuestFlaggedCompleted", eventStart, true))
|
||||||
|
local eventBlock = compat:sub(eventStart, eventEnd)
|
||||||
|
|
||||||
|
local clearPos = assert(eventBlock:find("ClearQuestCompleteTable(Questie.db.char.complete)", 1, true))
|
||||||
|
local fillPos = assert(eventBlock:find("GetQuestsCompleted(Questie.db.char.complete)", 1, true))
|
||||||
|
|
||||||
|
assert.is_true(clearPos < fillPos)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user