Skip to content

Commit

Permalink
Make sure the tags are loaded before anything else
Browse files Browse the repository at this point in the history
  • Loading branch information
mruwnik committed Aug 5, 2023
1 parent a1e8cb9 commit 2def4ca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/server-utils/stampy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ const convertToQuestion = ({name, values, updatedAt} = {} as AnswersRow): Questi
})

export const loadQuestionDetail = withCache('questionDetail', async (question: string) => {
// Make sure all tags are loaded. This shouldn't be needed often, as it's double cached
if (Object.keys(allTags).length === 0) {
const {data} = await loadTags('NEVER_RELOAD')
allTags = Object.fromEntries(data.map((r) => [r.name, r])) as Record<string, Tag>
}
const rows = (await getCodaRows(
QUESTION_DETAILS_TABLE,
// ids are now alphanumerical, so not possible to detect id by regex match for \d
Expand Down Expand Up @@ -348,9 +353,7 @@ export const loadTags = withCache('tags', async (): Promise<Tag[]> => {
.filter((q) => q.status == QuestionStatus.LIVE_ON_SITE)
.map((q) => [q.title, q.pageid])
)
const tags = rows.map((r) => toTag(r, nameToId))
allTags = Object.fromEntries(tags.map((r) => [r.name, r])) as Record<string, Tag>
return tags
return rows.map((r) => toTag(r, nameToId))
})

export const loadMoreAnswerDetails = withCache(
Expand Down

0 comments on commit 2def4ca

Please sign in to comment.