Fix edit history data access queries/usage
This commit is contained in:
parent
899e450eda
commit
2d4682685b
@ -23,9 +23,9 @@ export function getHistoryAfterId(id: string, count: number): Promise<EditHistor
|
|||||||
SELECT * FROM (
|
SELECT * FROM (
|
||||||
${baseQuery}
|
${baseQuery}
|
||||||
WHERE log_id > $1
|
WHERE log_id > $1
|
||||||
ORDER BY log_id ASC
|
ORDER BY revision_id ASC
|
||||||
LIMIT $2
|
LIMIT $2
|
||||||
) AS result_asc ORDER BY log_id DESC`,
|
) AS result_asc ORDER BY revision_id DESC`,
|
||||||
[id, count]
|
[id, count]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ export function getHistoryBeforeId(id: string, count: number): Promise<EditHisto
|
|||||||
return db.manyOrNone(`
|
return db.manyOrNone(`
|
||||||
${baseQuery}
|
${baseQuery}
|
||||||
WHERE log_id < $1
|
WHERE log_id < $1
|
||||||
ORDER BY log_id DESC
|
ORDER BY revision_id DESC
|
||||||
LIMIT $2
|
LIMIT $2
|
||||||
`, [id, count]);
|
`, [id, count]);
|
||||||
}
|
}
|
||||||
@ -42,23 +42,27 @@ export function getHistoryBeforeId(id: string, count: number): Promise<EditHisto
|
|||||||
export async function getLatestHistory(count: number) : Promise<EditHistoryEntry[]> {
|
export async function getLatestHistory(count: number) : Promise<EditHistoryEntry[]> {
|
||||||
return await db.manyOrNone(`
|
return await db.manyOrNone(`
|
||||||
${baseQuery}
|
${baseQuery}
|
||||||
ORDER BY log_id DESC
|
ORDER BY revision_id DESC
|
||||||
LIMIT $1
|
LIMIT $1
|
||||||
`, [count]);
|
`, [count]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getIdOlderThan(id: string): Promise<string> {
|
export async function getIdOlderThan(id: string): Promise<string> {
|
||||||
return await db.oneOrNone(`
|
const result = await db.oneOrNone<{revision_id:string}>(`
|
||||||
SELECT MAX(log_id) as log_id
|
SELECT MAX(log_id) as revision_id
|
||||||
FROM logs
|
FROM logs
|
||||||
WHERE log_id < $1
|
WHERE log_id < $1
|
||||||
`, [id]);
|
`, [id]);
|
||||||
|
|
||||||
|
return result?.revision_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getIdNewerThan(id: string): Promise<string> {
|
export async function getIdNewerThan(id: string): Promise<string> {
|
||||||
return await db.oneOrNone(`
|
const result = await db.oneOrNone<{revision_id:string}>(`
|
||||||
SELECT MIN(log_id) as log_id
|
SELECT MIN(log_id) as revision_id
|
||||||
FROM logs
|
FROM logs
|
||||||
WHERE log_id > $1
|
WHERE log_id > $1
|
||||||
`, [id]);
|
`, [id]);
|
||||||
|
|
||||||
|
return result?.revision_id;
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ async function getGlobalEditHistory(beforeId?: string, afterId?: string, count:
|
|||||||
editHistoryRecords = await getLatestHistory(count);
|
editHistoryRecords = await getLatestHistory(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newer = getIdNewerThan(editHistoryRecords[0]?.revision_id);
|
const newer = await getIdNewerThan(editHistoryRecords[0]?.revision_id);
|
||||||
const older = getIdOlderThan(editHistoryRecords[editHistoryRecords.length-1]?.revision_id);
|
const older = await getIdOlderThan(editHistoryRecords[editHistoryRecords.length-1]?.revision_id);
|
||||||
return {
|
return {
|
||||||
history: editHistoryRecords,
|
history: editHistoryRecords,
|
||||||
paging: {
|
paging: {
|
||||||
|
Loading…
Reference in New Issue
Block a user