-
Notifications
You must be signed in to change notification settings - Fork 0
β‘ Bolt: Optimize array lookups in filters to use Sets #187
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: main
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,13 @@ export default function ScheduleContainer({ initialSchedule, year }: Readonly<Sc | |||||||||||||||||||
| return initialSchedule; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession); | ||||||||||||||||||||
| /* | ||||||||||||||||||||
| * β‘ Bolt: Optimize array lookup from O(N*M) to O(N+M) | ||||||||||||||||||||
| * By converting the saved sessions array to a Set before filtering, | ||||||||||||||||||||
| * we prevent O(N^2) time complexity when filtering large session lists | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| const savedSessionIdsSet = new Set(savedSessionIds); | ||||||||||||||||||||
| const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIdsSet.has(s.id) || s.isServiceSession); | ||||||||||||||||||||
|
Comment on lines
+23
to
+29
Contributor
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. π οΈ Refactor suggestion | π Major Remove or simplify the explanatory comment. The comment explains what the code does (converting to Set, O(N*M) β O(N+M)), but the coding guidelines specify that code should be self-documenting and comments should only explain why non-obvious decisions were made. The Set conversion and its performance benefits are evident from the code itself. As per coding guidelines: "Code must be self-documenting. Only explain why non-obvious decisions were made in comments. DO NOT add inline comments explaining what code does." β»οΈ Proposed fix to remove the explanatory comment- /*
- * β‘ Bolt: Optimize array lookup from O(N*M) to O(N+M)
- * By converting the saved sessions array to a Set before filtering,
- * we prevent O(N^2) time complexity when filtering large session lists
- */
const savedSessionIdsSet = new Set(savedSessionIds);
const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIdsSet.has(s.id) || s.isServiceSession);π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| return initialSchedule.map((day) => ({ | ||||||||||||||||||||
| ...day, | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -129,7 +129,13 @@ export const groupTalksByTrack = (talks: Talk[]): Map<string, Talk[]> => { | |||||||||||||||||||
| */ | ||||||||||||||||||||
| export const getTalkSpeakersWithDetails = async (year: string | number, speakerIds: string[]): Promise<Speaker[]> => { | ||||||||||||||||||||
| const speakers = await getSpeakers(year); | ||||||||||||||||||||
| return speakers.filter((s) => speakerIds.includes(s.id)); | ||||||||||||||||||||
| /* | ||||||||||||||||||||
| * β‘ Bolt: Optimize array lookup from O(N*M) to O(N+M) | ||||||||||||||||||||
| * Converting speakerIds to a Set to prevent nested iterations | ||||||||||||||||||||
| * when matching speakers against the main speaker list | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| const speakerIdsSet = new Set(speakerIds); | ||||||||||||||||||||
| return speakers.filter((s) => speakerIdsSet.has(s.id)); | ||||||||||||||||||||
|
Comment on lines
+132
to
+138
Contributor
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. π οΈ Refactor suggestion | π Major Remove or simplify the explanatory comment. Similar to the change in As per coding guidelines: "Code must be self-documenting. Only explain why non-obvious decisions were made in comments. DO NOT add inline comments explaining what code does." β»οΈ Proposed fix to remove the explanatory comment- /*
- * β‘ Bolt: Optimize array lookup from O(N*M) to O(N+M)
- * Converting speakerIds to a Set to prevent nested iterations
- * when matching speakers against the main speaker list
- */
const speakerIdsSet = new Set(speakerIds);
return speakers.filter((s) => speakerIdsSet.has(s.id));π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const getRelatedTalksByTrack = async (year: string | number, track: string, excludeTalkId: string, limit: number = 5): Promise<Talk[]> => { | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
While documenting learning is valuable, this entry includes a specific date. Per the project guidelines, we should avoid referencing specific dates in non-code areas unless strictly necessary for versioning or legal requirements. Consider removing the date from the header to keep the log focused on the technical learning.