Paginate Olist monitor history
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m17s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m17s
This commit is contained in:
@@ -102,13 +102,24 @@ const getConnection = async () => {
|
||||
return result.rows[0] || null;
|
||||
};
|
||||
|
||||
const listSyncRuns = async (limit = 5) => {
|
||||
const result = await pool.query(`
|
||||
const listSyncRuns = async ({ page = 1, pageSize = 5 } = {}) => {
|
||||
const normalizedPageSize = Math.max(1, Math.min(Number(pageSize) || 5, 20));
|
||||
const normalizedPage = Math.max(1, Number(page) || 1);
|
||||
const offset = (normalizedPage - 1) * normalizedPageSize;
|
||||
const [runsResult, countResult] = await Promise.all([
|
||||
pool.query(`
|
||||
SELECT * FROM olist_sync_runs
|
||||
ORDER BY started_at DESC
|
||||
LIMIT $1;
|
||||
`, [Math.max(1, Math.min(Number(limit) || 5, 20))]);
|
||||
return result.rows.map(mapRun);
|
||||
LIMIT $1 OFFSET $2;
|
||||
`, [normalizedPageSize, offset]),
|
||||
pool.query('SELECT COUNT(*)::int AS count FROM olist_sync_runs;')
|
||||
]);
|
||||
return {
|
||||
items: runsResult.rows.map(mapRun),
|
||||
total: Number(countResult.rows[0]?.count || 0),
|
||||
page: normalizedPage,
|
||||
pageSize: normalizedPageSize
|
||||
};
|
||||
};
|
||||
|
||||
const hasScheduledSyncToday = async () => {
|
||||
@@ -252,8 +263,14 @@ const markInterruptedOlistRuns = async () => {
|
||||
return result.rowCount || 0;
|
||||
};
|
||||
|
||||
const getOlistStatus = async () => {
|
||||
const [connection, runs, productCache] = await Promise.all([getConnection(), listSyncRuns(), getProductCacheProgress()]);
|
||||
const getOlistStatus = async ({ runsPage = 1, runsPageSize = 5 } = {}) => {
|
||||
const [connection, syncRuns, productCache, latestRunResult, completedRunResult] = await Promise.all([
|
||||
getConnection(),
|
||||
listSyncRuns({ page: runsPage, pageSize: runsPageSize }),
|
||||
getProductCacheProgress(),
|
||||
pool.query('SELECT * FROM olist_sync_runs ORDER BY started_at DESC LIMIT 1;'),
|
||||
pool.query("SELECT EXISTS (SELECT 1 FROM olist_sync_runs WHERE status = 'completed') AS exists;")
|
||||
]);
|
||||
return {
|
||||
configured: isOlistConfigured(),
|
||||
connected: Boolean(connection),
|
||||
@@ -261,7 +278,12 @@ const getOlistStatus = async () => {
|
||||
syncInProgress: Boolean(activeSync),
|
||||
nextScheduledSyncAt,
|
||||
productCache,
|
||||
runs
|
||||
latestRun: latestRunResult.rows[0] ? mapRun(latestRunResult.rows[0]) : null,
|
||||
hasCompletedRun: Boolean(completedRunResult.rows[0]?.exists),
|
||||
runs: syncRuns.items,
|
||||
runsTotal: syncRuns.total,
|
||||
runsPage: syncRuns.page,
|
||||
runsPageSize: syncRuns.pageSize
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user