From ea3653f2bc9c8118a3a50004ebc15f585c038988 Mon Sep 17 00:00:00 2001 From: marcin2121 <13873718+marcin2121@users.noreply.github.com> Date: Tue, 31 Mar 2026 19:28:02 +0000 Subject: [PATCH] perf(spin-wheel): optimize array filtering by using Set Replaced `Array.includes` with `Set.has` when filtering available prizes in the `spinWheel` action. This reduces lookup time complexity from O(n) to O(1), improving overall filtering performance. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- app/actions/spin-wheel.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/actions/spin-wheel.ts b/app/actions/spin-wheel.ts index ef2d6ad..a0a8deb 100644 --- a/app/actions/spin-wheel.ts +++ b/app/actions/spin-wheel.ts @@ -49,9 +49,10 @@ export async function spinWheel() { const unspentCoupons = userCurrentCoupons?.filter((c: any) => (c.current_usage || 0) < (c.usage_limit || 1)) || []; const usedTitles = unspentCoupons.map((c: any) => c.title); + const usedTitlesSet = new Set(usedTitles); // Filtrujemy nagrody - const availablePrizes = prizes.filter((p: any) => !usedTitles.includes(p.title)); + const availablePrizes = prizes.filter((p: any) => !usedTitlesSet.has(p.title)); if (availablePrizes.length === 0) { return { error: 'Posiadasz już wszystkie rabaty! Zużyj przynajmniej jeden z nich pod kasą, by zwolnić miejsce.' }