From e731b6229cfefb577c47beb9feefe632af6be333 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Mar 2026 21:08:53 +0000 Subject: [PATCH 1/3] perf(movie-helper): extract CLEAN_TEXT_REGEX to constant Extract the `/(^|\n|\r|\t)/gm` regex (used for cleaning text nodes) into a module-scoped constant `CLEAN_TEXT_REGEX` in `src/helpers/movie.helper.ts`. This avoids redundant regex compilation during high-iteration DOM traversals in `getMovieTrivia` and `getMovieDescriptions`. Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com> --- src/helpers/movie.helper.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helpers/movie.helper.ts b/src/helpers/movie.helper.ts index b908f3fa..7eb31d34 100644 --- a/src/helpers/movie.helper.ts +++ b/src/helpers/movie.helper.ts @@ -28,6 +28,9 @@ import { parseLastIdFromUrl } from './global.helper'; +// Optimization: Extract regex from mapping loops to avoid recompilation overhead +const CLEAN_TEXT_REGEX = /(\r\n|\n|\r|\t)/gm; + const CREATOR_LABELS: Record< string, Record @@ -264,7 +267,7 @@ export const getMovieRandomPhoto = (el: HTMLElement | null): string => { export const getMovieTrivia = (el: HTMLElement | null): string[] => { const triviaNodes = el.querySelectorAll('.article-trivia ul li'); if (triviaNodes?.length) { - return triviaNodes.map((node) => node.textContent.trim().replace(/(\r\n|\n|\r|\t)/gm, '')); + return triviaNodes.map((node) => node.textContent.trim().replace(CLEAN_TEXT_REGEX, '')); } else { return null; } @@ -273,7 +276,7 @@ export const getMovieTrivia = (el: HTMLElement | null): string[] => { export const getMovieDescriptions = (el: HTMLElement): string[] => { return el .querySelectorAll('.body--plots .plot-full p, .body--plots .plots .plots-item p') - .map((movie) => movie.textContent?.trim().replace(/(\r\n|\n|\r|\t)/gm, '')); + .map((movie) => movie.textContent?.trim().replace(CLEAN_TEXT_REGEX, '')); }; const parseMoviePeople = (el: HTMLElement): CSFDMovieCreator[] => { From 6ef34aea24680295d0c6c7088d920cfe49a80189 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Mar 2026 21:12:50 +0000 Subject: [PATCH 2/3] perf(movie-helper): extract CLEAN_TEXT_REGEX to constant Extract the `/(^|\n|\r|\t)/gm` regex (used for cleaning text nodes) into a module-scoped constant `CLEAN_TEXT_REGEX` in `src/helpers/movie.helper.ts`. This avoids redundant regex compilation during high-iteration DOM traversals in `getMovieTrivia` and `getMovieDescriptions`. Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com> From 4fb965c778ca978d90714b69f0582137f0876f2b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Mar 2026 21:16:07 +0000 Subject: [PATCH 3/3] perf(movie-helper): extract CLEAN_TEXT_REGEX to constant Extract the `/(^|\n|\r|\t)/gm` regex (used for cleaning text nodes) into a module-scoped constant `CLEAN_TEXT_REGEX` in `src/helpers/movie.helper.ts`. This avoids redundant regex compilation during high-iteration DOM traversals in `getMovieTrivia` and `getMovieDescriptions`. Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com>