Repository navigation
feat: [performance improvement] optimize displayTag resolution #271
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鈥檒l 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -40,8 +40,22 @@ export async function generateMetadata({ params }: { params: Promise<{ tag: stri | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 targetTag = decodedTag.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const state: { displayTag?: string } = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const talk of allTalks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const talkTags = getTagsFromTalk(talk); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const match = talkTags.some((t) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (t.replaceAll(" ", "-").toLowerCase() === targetTag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state.displayTag = t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (match) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const displayTag = state.displayTag ?? decodedTag.replaceAll("-", " "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: `Talks tagged "${displayTag}" - DevBcn ${year}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,15 +72,22 @@ export default async function Page({ params }: { params: Promise<{ tag: string } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 targetTag = decodedTag.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const state: { displayTag?: string } = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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() === targetTag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!state.displayTag) state.displayTag = t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const displayTag = state.displayTag ?? decodedTag.replaceAll("-", " "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (filteredTalks.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| notFound(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+75
to
93
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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,8 +47,22 @@ 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 targetTag = decodedTag.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const state: { displayTag?: string } = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const talk of allTalks) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const talkTags = getTagsFromTalk(talk); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const match = talkTags.some((t) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (t.replaceAll(" ", "-").toLowerCase() === targetTag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state.displayTag = t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (match) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const displayTag = state.displayTag ?? decodedTag.replaceAll("-", " "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+65
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. Instead of using an imperative |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: `Talks tagged "${displayTag}" - DevBcn ${year}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -64,15 +78,22 @@ 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 targetTag = decodedTag.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const state: { displayTag?: string } = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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() === targetTag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!state.displayTag) state.displayTag = t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const displayTag = state.displayTag ?? decodedTag.replaceAll("-", " "); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (filteredTalks.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| notFound(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+81
to
99
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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 an imperative
for...ofloop with a manualbreakand mutating a temporarystateobject, you can achieve the same early-breaking single-pass lookup in a much more idiomatic and declarative way using standard array methods like.find()and.some().