-
-
Notifications
You must be signed in to change notification settings - Fork 14
⚡ Bolt: [performance improvement] optimize parseSearchPeople #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,29 +42,44 @@ export const getSearchOrigins = (el: HTMLElement): string[] => { | |
| return originsAll?.split('/').map((country) => country.trim()); | ||
| }; | ||
|
|
||
| export const parseSearchPeople = ( | ||
| el: HTMLElement, | ||
| type: 'directors' | 'actors' | ||
| ): CSFDMovieCreator[] => { | ||
| let who: Creator; | ||
| if (type === 'directors') who = 'Režie:'; | ||
| if (type === 'actors') who = 'Hrají:'; | ||
| export const getSearchCreators = ( | ||
| el: HTMLElement | ||
| ): { directors: CSFDMovieCreator[]; actors: CSFDMovieCreator[] } => { | ||
| const result = { directors: [] as CSFDMovieCreator[], actors: [] as CSFDMovieCreator[] }; | ||
|
|
||
| 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 foundDirectors = false; | ||
| let foundActors = false; | ||
|
|
||
| if (peopleNode) { | ||
| const people = Array.from(peopleNode.querySelectorAll('a')) as unknown as HTMLElement[]; | ||
| for (const node of pNodes) { | ||
| if (foundDirectors && foundActors) break; | ||
|
|
||
| return people.map((person) => { | ||
| return { | ||
| id: parseIdFromUrl(person.attributes.href), | ||
| name: person.innerText.trim(), | ||
| url: `https://www.csfd.cz${person.attributes.href}` | ||
| }; | ||
| }); | ||
| } else { | ||
| return []; | ||
| const text = node.textContent; | ||
| if (!foundDirectors && text.includes('Režie:')) { | ||
| result.directors = (Array.from(node.querySelectorAll('a')) as unknown as HTMLElement[]).map( | ||
| (person) => { | ||
| return { | ||
| id: parseIdFromUrl(person.attributes.href), | ||
| name: person.innerText.trim(), | ||
| url: `https://www.csfd.cz${person.attributes.href}` | ||
| }; | ||
|
Comment on lines
+63
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check how other helpers handle URL construction and if language-specific URLs are used
rg -n "getUrlByLanguage|https://www.csfd" --type ts src/Repository: bartholomej/node-csfd-api Length of output: 1726 🏁 Script executed: cat -n src/services/search.service.ts | head -60Repository: bartholomej/node-csfd-api Length of output: 2759 🏁 Script executed: # Check if there are any comments explaining the URL construction pattern
rg -B 3 -A 1 "https://www.csfd.cz" src/helpers/search.helper.tsRepository: bartholomej/node-csfd-api Length of output: 461 🏁 Script executed: # Check the function signature of the search helper to see what parameters it receives
rg -B 5 "export.*parse" src/helpers/search.helper.ts | head -40Repository: bartholomej/node-csfd-api Length of output: 51 🏁 Script executed: sed -n '40,80p' src/services/search.service.tsRepository: bartholomej/node-csfd-api Length of output: 1289 🏁 Script executed: cat -n src/helpers/search.helper.tsRepository: bartholomej/node-csfd-api Length of output: 3647 🏁 Script executed: cat -n src/helpers/search-creator.helper.tsRepository: bartholomej/node-csfd-api Length of output: 662 🏁 Script executed: cat -n src/helpers/search-user.helper.tsRepository: bartholomej/node-csfd-api Length of output: 1076 🏁 Script executed: # Check if getSearchCreators is called with language parameter anywhere
rg -B 3 -A 3 "getSearchCreators" src/Repository: bartholomej/node-csfd-api Length of output: 1386 Fix hardcoded base URL in creator URLs within search results. The helper hardcodes This causes nested creators within movie search results to ignore the selected language. Either:
🤖 Prompt for AI Agents |
||
| } | ||
| ); | ||
| foundDirectors = true; | ||
| } else if (!foundActors && text.includes('Hrají:')) { | ||
| result.actors = (Array.from(node.querySelectorAll('a')) as unknown as HTMLElement[]).map( | ||
| (person) => { | ||
| return { | ||
| id: parseIdFromUrl(person.attributes.href), | ||
| name: person.innerText.trim(), | ||
| url: `https://www.csfd.cz${person.attributes.href}` | ||
| }; | ||
| } | ||
| ); | ||
| foundActors = true; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add optional chaining on
textContentfor robustness.Per coding guidelines, helpers should never assume an element exists. If
node.textContentreturnsnullorundefined, calling.includes()will throw a TypeError.🛡️ Proposed fix
As per coding guidelines: "Never assume an element exists. CSFD changes layouts. Use optional chaining
?.ortry/catchinside helpers for robust scraping."📝 Committable suggestion
🤖 Prompt for AI Agents