Repository navigation
feat: [performance improvement] #273
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 |
|---|---|---|
|
|
@@ -47,8 +47,21 @@ export async function generateMetadata({ params }: Readonly<TagPageProps>): Prom | |
|
|
||
| const sessionGroups = await getTalks(year); | ||
| const allTalks = sessionGroups.flatMap((group) => group.sessions); | ||
| const displayTag = | ||
| allTalks.flatMap(getTagsFromTalk).find((t) => t.replaceAll(" ", "-").toLowerCase() === decodedTag.toLowerCase()) ?? decodedTag.replaceAll("-", " "); | ||
| const targetTagLower = decodedTag.toLowerCase(); | ||
| const state = { displayTag: undefined as string | undefined }; | ||
|
|
||
| for (const talk of allTalks) { | ||
| const talkTags = getTagsFromTalk(talk); | ||
| for (const t of talkTags) { | ||
| if (t.replaceAll(" ", "-").toLowerCase() === targetTagLower) { | ||
| state.displayTag = t; | ||
| break; | ||
| } | ||
| } | ||
| if (state.displayTag) break; | ||
| } | ||
|
|
||
| const displayTag = state.displayTag ?? decodedTag.replaceAll("-", " "); | ||
|
|
||
| return { | ||
| title: `Talks tagged "${displayTag}" - DevBcn ${year}`, | ||
|
|
@@ -64,15 +77,23 @@ export default async function TagPage({ params }: Readonly<TagPageProps>) { | |
| const sessionGroups = await getTalks(year); | ||
| const allTalks = sessionGroups.flatMap((group) => group.sessions); | ||
|
|
||
| const displayTag = | ||
| allTalks.flatMap(getTagsFromTalk).find((t) => t.replaceAll(" ", "-").toLowerCase() === decodedTag.toLowerCase()) ?? decodedTag.replaceAll("-", " "); | ||
| const targetTagLower = decodedTag.toLowerCase(); | ||
| const state = { displayTag: undefined as string | undefined }; | ||
|
|
||
| const filteredTalks = allTalks.filter((talk) => { | ||
| const talkTags = getTagsFromTalk(talk); | ||
|
|
||
| return talkTags.some((t) => t.replaceAll(" ", "-").toLowerCase() === decodedTag.toLowerCase()); | ||
| return talkTags.some((t) => { | ||
| if (t.replaceAll(" ", "-").toLowerCase() === targetTagLower) { | ||
| if (!state.displayTag) state.displayTag = t; | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
| }); | ||
|
|
||
| const displayTag = state.displayTag ?? decodedTag.replaceAll("-", " "); | ||
|
Comment on lines
+80
to
+95
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. Mutating external state (like |
||
|
|
||
| if (filteredTalks.length === 0) { | ||
| notFound(); | ||
| } | ||
|
|
||
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.
Instead of using a nested loop with a mutable helper
stateobject, you can simplify the early-break logic by using a standardfor...ofloop combined with.find(). This avoids the extra level of nesting and the state object, making the code more readable and maintainable.