diff --git a/operations/journal.graphql b/operations/journal.graphql index 85cd09f..0fa770c 100644 --- a/operations/journal.graphql +++ b/operations/journal.graphql @@ -37,6 +37,7 @@ query GetUserInfo($userInfoUname: String!) { } best3 { w + r ymd e { id diff --git a/server/db/resolvers/journal.js b/server/db/resolvers/journal.js index 10cd9ce..878f57a 100644 --- a/server/db/resolvers/journal.js +++ b/server/db/resolvers/journal.js @@ -95,49 +95,37 @@ export const GetUserInfo = async ( requestorUID, requestedUserIdentifier, identi const GetBestOfficialLiftsOf = async ( uid, onlyTheseTypes )=>{ let officialEnames = getAllOfficialEnames(onlyTheseTypes); - let officialETags = getAllOfficialETags(onlyTheseTypes); - - // let result = await query(` SELECT - // A.wkg AS wkg, - // B.nombre AS ename, - // B.id AS eid, - // C.fecha_del_log AS ymd - - // FROM erows AS A - // INNER JOIN exercises AS B ON B.id=A.eid - // INNER JOIN logs AS C ON A.logid=C.id - // WHERE - // A.uid=? - // AND A.reps>0 AND A.type=0 - // AND (B.nombre IN (?) OR ${ officialETags.map( tag=>`B.nombre LIKE '%${tag}' OR B.nombre LIKE '%${tag} %'` ).join(" OR ") }) - - // GROUP BY B.id - // ORDER BY wkg DESC`, [ uid, officialEnames ]); - let result = await query(`SELECT + let officialETags = getAllOfficialETags(onlyTheseTypes); + + let result = await query(` SELECT e.id AS eid, e.nombre AS ename, - er.wkg , + er.wkg, + er.reps, l.fecha_del_log AS ymd - FROM - erows er - JOIN - exercises e ON er.eid = e.id - JOIN - logs l ON er.logid = l.id - WHERE - er.uid=? AND er.reps>0 AND er.type=0 - AND (e.nombre IN (?) OR ${ officialETags.map( tag=>`e.nombre LIKE '%${tag}' OR e.nombre LIKE '%${tag} %'` ).join(" OR ") }) - AND - (er.eid, er.wkg) IN ( - SELECT - eid, MAX(wkg) - FROM - erows - WHERE uid=? AND erows.reps>0 - GROUP BY - eid - ) - ORDER BY wkg DESC, ymd ASC`, [ uid, officialEnames, uid ]); + FROM erows er + JOIN exercises e ON er.eid = e.id + JOIN logs l ON er.logid = l.id + WHERE er.uid = ? AND er.reps>0 + AND EXISTS ( + SELECT 1 + FROM erows er_sub + JOIN exercises e2 ON er_sub.eid = e2.id + WHERE er_sub.uid = er.uid + AND er_sub.reps > 0 + AND er_sub.eid = er.eid + AND er_sub.wkg = ( + SELECT MAX(erows_sub.wkg) + FROM erows erows_sub + WHERE erows_sub.uid = er_sub.uid + AND erows_sub.eid = er_sub.eid + AND erows_sub.reps > 0 + ) + AND er_sub.type = 0 + AND (e2.nombre IN (?) OR ${ officialETags.map( tag=>`e2.nombre LIKE '%${tag}' OR e2.nombre LIKE '%${tag} %'` ).join(" OR ") }) + ) + ORDER BY er.wkg DESC, l.fecha_del_log ASC + `, [ uid, officialEnames ]); return result.map( row => ({ ...row, @@ -299,7 +287,8 @@ export const JournalResolver = { if( !ex ) return null; return { - w: ex?.wkg || 0, + w: ex.wkg ?? 0, + r: ex.reps ?? 1, ymd: ex.ymd, e: { id : ex.eid, diff --git a/server/db/schema/JournalDay.js b/server/db/schema/JournalDay.js index 6873bec..f2a0489 100644 --- a/server/db/schema/JournalDay.js +++ b/server/db/schema/JournalDay.js @@ -8,6 +8,7 @@ const $types = gql` type BestLift { w:Float! + r:Int! ymd:YMD! e:Exercise! } diff --git a/server/db/schema/types.ts b/server/db/schema/types.ts index 7cf6738..a381cbf 100644 --- a/server/db/schema/types.ts +++ b/server/db/schema/types.ts @@ -70,6 +70,7 @@ export type BestEStat = { export type BestLift = { __typename?: 'BestLift'; e: Exercise; + r: Scalars['Int']; w: Scalars['Float']; ymd: Scalars['YMD']; }; @@ -1672,7 +1673,7 @@ export type GetUserInfoQueryVariables = Exact<{ }>; -export type GetUserInfoQuery = { __typename?: 'Query', userInfo: { __typename?: 'UserInfo', daysLogged: number, user: { __typename?: 'User', id: string, avatarhash: string, uname: string, cc?: string | null, slvl?: number | null, sok?: number | null, sleft?: number | null, age?: number | null, bw?: number | null, private?: number | null, isf?: number | null, joined?: string | null, usekg?: number | null, forumRole?: ForumRoleKey | null, custom1RM?: number | null, est1RMFactor?: number | null, jranges?: Array | null, estimate1RMFormula?: string | null, socialLinks?: Array | null }, forum?: { __typename?: 'ForumStatus', posts?: number | null, role?: { __typename?: 'ForumRole', title: string } | null } | null, best3?: Array<{ __typename?: 'BestLift', w: number, ymd: any, e: { __typename?: 'Exercise', id: string, name: string, type?: string | null } }> | null } }; +export type GetUserInfoQuery = { __typename?: 'Query', userInfo: { __typename?: 'UserInfo', daysLogged: number, user: { __typename?: 'User', id: string, avatarhash: string, uname: string, cc?: string | null, slvl?: number | null, sok?: number | null, sleft?: number | null, age?: number | null, bw?: number | null, private?: number | null, isf?: number | null, joined?: string | null, usekg?: number | null, forumRole?: ForumRoleKey | null, custom1RM?: number | null, est1RMFactor?: number | null, jranges?: Array | null, estimate1RMFormula?: string | null, socialLinks?: Array | null }, forum?: { __typename?: 'ForumStatus', posts?: number | null, role?: { __typename?: 'ForumRole', title: string } | null } | null, best3?: Array<{ __typename?: 'BestLift', w: number, r: number, ymd: any, e: { __typename?: 'Exercise', id: string, name: string, type?: string | null } }> | null } }; export type GetUserBasicInfoQueryVariables = Exact<{ of?: InputMaybe; diff --git a/wxr-dev-db/sql/0_db-setup.sql b/wxr-dev-db/sql/0_db-setup.sql index 57e76df..1c72d55 100644 --- a/wxr-dev-db/sql/0_db-setup.sql +++ b/wxr-dev-db/sql/0_db-setup.sql @@ -62,7 +62,7 @@ CREATE TABLE IF NOT EXISTS `erows` ( INDEX `idx_erows_reps` (`reps`), INDEX `idx_erows_wkg_reps` (`wkg`, `reps`), INDEX `idx_erows_just_logid` (`logid`), - + INDEX `idx_erows_eid_wkg` (`eid`, `wkg`), PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;