From 8b5a27f9beac1bc99e12dbfaa850063cc3285f4f Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 31 Oct 2026 06:36:42 -0500 Subject: [PATCH] Expire cached aggro on UNIT_TARGET UnitHasAggro caches a positive answer for 1s and a negative one for 0.3s, so the aggro glow lagged a taunt or a mob turning on a healer by up to that long. A retarget now expires the entries it can affect: every unit that had aggro and the retargeting unit's new target. The rest stay cached, so the scan runs no more often. Mobs without a token of their own fire it with their GUID, and "target" composes. --- api/unitframes.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/unitframes.lua b/api/unitframes.lua index 647df472..08a392ed 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -313,6 +313,7 @@ function pfUI.api.UnitHasAggro(unit) if not data then data = { }; aggrodata[unit] = data end data.check = now data.state = 0 + data.guid = UnitGUID(unit) if UnitExists(unit) and UnitIsFriend(unit, "player") then for i = 1, table.getn(aggroScan) do @@ -329,6 +330,21 @@ function pfUI.api.UnitHasAggro(unit) return data.state end +-- A unit turned to someone else, so two kinds of cached answer may be stale: +-- every unit that had aggro (the attacker may have left it) and the new +-- target. Those recompute on their next read instead of riding out the +-- cache; the rest stay cached, since the retarget changes nothing for them. +-- Units without a token of their own (a raid member's target) still fire it +-- with their GUID, which composes with "target" like any token. +pfUI.events:RegisterFrameEventAndCallback("UNIT_TARGET", function(_, unit) + local target = UnitGUID(unit .. "target") + for _, data in pairs(aggrodata) do + if data.state > 0 or (target and data.guid == target) then + data.check = 0 + end + end +end) + function pfUI.uf:UpdateVisibility() local self = self or this