| 57 | |
| 58 | // Pure helper: add a choice ad set to the choice cache |
| 59 | function addToChoiceCache(ctrl: GravityController, ads: AdResponse[]): void { |
| 60 | // ZeroClick offer responses must not be stored for later display. Keep them |
| 61 | // out of the rotation cache and only render them for the live request. |
| 62 | if (ads.some((ad) => ad.provider === 'zeroclick')) return |
| 63 | |
| 64 | // Deduplicate by checking if any set has the same first impUrl |
| 65 | const key = ads[0]?.impUrl |
| 66 | if (key && ctrl.choiceCache.some((set) => set[0]?.impUrl === key)) return |
| 67 | if (ctrl.choiceCache.length >= MAX_AD_CACHE_SIZE) ctrl.choiceCache.shift() |
| 68 | ctrl.choiceCache.push(ads) |
| 69 | } |
| 70 | |
| 71 | // Pure helper: get the next cached choice ad set |
| 72 | function nextFromChoiceCache(ctrl: GravityController): AdResponse[] | null { |