Skip to content

Commit 5169563

Browse files
committed
Blacklist not-found units while in combat
This change avoid repetitive full-recursive search on UIParent for units not shown by unitframes
1 parent d44c924 commit 5169563

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

LibGetFrame-1.0.lua

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
local MAJOR_VERSION = "LibGetFrame-1.0"
2-
local MINOR_VERSION = 3
2+
local MINOR_VERSION = 4
33
if not LibStub then error(MAJOR_VERSION .. " requires LibStub.") end
44
local lib, oldversion = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
55
if not lib then return end
66

7+
local InCombatLockdown, UnitIsUnit, tinsert = InCombatLockdown, UnitIsUnit, tinsert
8+
79
local maxDepth = 50
810

911
local defaultFramePriorities = {
@@ -60,13 +62,15 @@ local defaultTargettargetFrames = {
6062
}
6163

6264
local GetFramesCache = {}
65+
local GetFramesCacheLockdown = {}
6366

6467
local GetFramesCacheListener = CreateFrame("Frame")
6568
GetFramesCacheListener:RegisterEvent("PLAYER_REGEN_DISABLED")
6669
GetFramesCacheListener:RegisterEvent("PLAYER_REGEN_ENABLED")
6770
GetFramesCacheListener:RegisterEvent("GROUP_ROSTER_UPDATE")
6871
GetFramesCacheListener:SetScript("OnEvent", function(self, event, ...)
6972
GetFramesCache = {}
73+
GetFramesCacheLockdown = {}
7074
end)
7175

7276
local function FindButtonsForUnit(frame, target, depth)
@@ -94,6 +98,9 @@ local function FindButtonsForUnit(frame, target, depth)
9498
end
9599

96100
local function GetFrames(target, ignoredFrames)
101+
if GetFramesCacheLockdown[target] then
102+
return {}
103+
end
97104
if not UnitExists(target) then
98105
if type(target) == "string" and target:find("Player") then
99106
target = select(6,GetPlayerInfoByGUID(target))
@@ -120,6 +127,11 @@ local function GetFrames(target, ignoredFrames)
120127

121128
frames = #frames > 0 and frames or FindButtonsForUnit(UIParent, target, 0)
122129

130+
-- if we are in combat and no frame was found we want to blacklist unit until cache is wiped
131+
if #frames == 0 and InCombatLockdown() then
132+
GetFramesCacheLockdown[target] = true
133+
end
134+
123135
-- filter ignored frames
124136
for k, frame in pairs(frames) do
125137
local name = frame:GetName()

0 commit comments

Comments
 (0)