MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / addToChoiceCache

Function addToChoiceCache

cli/src/hooks/use-gravity-ad.ts:59–69  ·  view source on GitHub ↗
(ctrl: GravityController, ads: AdResponse[])

Source from the content-addressed store, hash-verified

57
58// Pure helper: add a choice ad set to the choice cache
59function 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
72function nextFromChoiceCache(ctrl: GravityController): AdResponse[] | null {

Callers 1

useGravityAdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected