From 2a3d767301396f507d5f5030358b4491a242d7af Mon Sep 17 00:00:00 2001 From: Adrian Rocke Date: Sat, 16 Nov 2024 21:05:40 -0600 Subject: [PATCH] fix: progress query --- .../[code]/books/[bookId]/progress/route.ts | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/app/[locale]/(authenticated)/translate/[code]/books/[bookId]/progress/route.ts b/app/[locale]/(authenticated)/translate/[code]/books/[bookId]/progress/route.ts index ed845c9..c297fc0 100644 --- a/app/[locale]/(authenticated)/translate/[code]/books/[bookId]/progress/route.ts +++ b/app/[locale]/(authenticated)/translate/[code]/books/[bookId]/progress/route.ts @@ -39,21 +39,15 @@ async function fetchBookProgress(bookId: number, languageCode: string): Promise< WHERE v."bookId" = b.id ) AS "wordCount", ( - SELECT - COUNT(*) - FROM ( - SELECT ph.id FROM "Phrase" AS ph - JOIN "Gloss" AS g ON g."phraseId" = ph.id - WHERE ph."languageId" = (SELECT id FROM "Language" WHERE code = $2) - AND ph."deletedAt" IS NULL - AND EXISTS ( - SELECT FROM "Verse" AS v - JOIN "Word" AS w ON w."verseId" = v.id - JOIN "PhraseWord" AS phw ON phw."wordId" = w.id - WHERE phw."phraseId" = ph.id - AND v."bookId" = b.id - ) - ) AS ph + SELECT COUNT(*) FROM "Phrase" AS ph + LEFT JOIN "Gloss" AS g ON g."phraseId" = ph.id + JOIN "PhraseWord" AS phw ON phw."phraseId" = ph.id + JOIN "Word" AS w ON w.id = phw."wordId" + JOIN "Verse" AS v ON v.id = w."verseId" + WHERE ph."languageId" = (SELECT id FROM "Language" WHERE code = $2) + AND ph."deletedAt" IS NULL + AND v."bookId" = b.id + AND g.state = 'APPROVED' ) AS "approvedCount" FROM "Book" AS b WHERE b.id = $1