From b6870c5ffcc1dd7af29666489b6e13d1cdcc51af Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2026 19:54:34 +0000 Subject: [PATCH] perf(search): optimize node-html-parser node iteration in parseSearchPeople Replaced Array.from().find() with a standard for...of loop to prevent unnecessary array allocations during querySelectorAll traversals and allow early exit. Removes redundant array casting. Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com> --- src/helpers/search.helper.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/helpers/search.helper.ts b/src/helpers/search.helper.ts index 7ec62343..32f8f4e6 100644 --- a/src/helpers/search.helper.ts +++ b/src/helpers/search.helper.ts @@ -50,12 +50,21 @@ export const parseSearchPeople = ( if (type === 'directors') who = 'Režie:'; if (type === 'actors') who = 'Hrají:'; - const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) => - el.textContent.includes(who) - ); + const pNodes = el && el.querySelectorAll('.article-content p'); + let peopleNode: HTMLElement | null = null; + if (pNodes) { + for (const p of pNodes) { + if (p.textContent.includes(who)) { + peopleNode = p; + break; + } + } + } if (peopleNode) { - const people = Array.from(peopleNode.querySelectorAll('a')) as unknown as HTMLElement[]; + // Optimization: Avoid Array.from allocation and use direct mapping if possible, + // though NodeList might require mapping. In our environment querySelectorAll returns an array. + const people = peopleNode.querySelectorAll('a'); return people.map((person) => { return {