From 2d4682685b382335e5f50f5e7e01aad82d5c7c6a Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Wed, 29 Jan 2020 17:24:44 +0000 Subject: [PATCH] Fix edit history data access queries/usage --- app/src/api/dataAccess/editHistory.ts | 20 ++++++++++++-------- app/src/api/services/editHistory.ts | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/api/dataAccess/editHistory.ts b/app/src/api/dataAccess/editHistory.ts index 828263f7..b14933cb 100644 --- a/app/src/api/dataAccess/editHistory.ts +++ b/app/src/api/dataAccess/editHistory.ts @@ -23,9 +23,9 @@ export function getHistoryAfterId(id: string, count: number): Promise $1 - ORDER BY log_id ASC + ORDER BY revision_id ASC LIMIT $2 - ) AS result_asc ORDER BY log_id DESC`, + ) AS result_asc ORDER BY revision_id DESC`, [id, count] ); } @@ -34,7 +34,7 @@ export function getHistoryBeforeId(id: string, count: number): Promise { return await db.manyOrNone(` ${baseQuery} - ORDER BY log_id DESC + ORDER BY revision_id DESC LIMIT $1 `, [count]); } export async function getIdOlderThan(id: string): Promise { - return await db.oneOrNone(` - SELECT MAX(log_id) as log_id + const result = await db.oneOrNone<{revision_id:string}>(` + SELECT MAX(log_id) as revision_id FROM logs WHERE log_id < $1 `, [id]); + + return result?.revision_id; } export async function getIdNewerThan(id: string): Promise { - return await db.oneOrNone(` - SELECT MIN(log_id) as log_id + const result = await db.oneOrNone<{revision_id:string}>(` + SELECT MIN(log_id) as revision_id FROM logs WHERE log_id > $1 `, [id]); + + return result?.revision_id; } diff --git a/app/src/api/services/editHistory.ts b/app/src/api/services/editHistory.ts index 33c00698..5e0f53fe 100644 --- a/app/src/api/services/editHistory.ts +++ b/app/src/api/services/editHistory.ts @@ -13,8 +13,8 @@ async function getGlobalEditHistory(beforeId?: string, afterId?: string, count: editHistoryRecords = await getLatestHistory(count); } - const newer = getIdNewerThan(editHistoryRecords[0]?.revision_id); - const older = getIdOlderThan(editHistoryRecords[editHistoryRecords.length-1]?.revision_id); + const newer = await getIdNewerThan(editHistoryRecords[0]?.revision_id); + const older = await getIdOlderThan(editHistoryRecords[editHistoryRecords.length-1]?.revision_id); return { history: editHistoryRecords, paging: {