mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-06 07:10:41 +08:00
Use MikroORM's official Node SQLite dialect with bounded database isolation, preserve legacy schema and data for rollback, and require Node 22.17 or newer. Update Debian runtimes and retain ARMv6 musl compatibility without a SQLite addon. Complete short archive writes, stop orphaned SQL workers after owner death, preserve buffered startup requests, and prestart the archived backend on every platform. Cover real package installation, migration, failure recovery, and legacy database compatibility. Keep authentication storage failures distinct from expired sessions with a pinned Keyv runtime, propagated cache errors, and retryable HTTP 503 responses. Preserve genuine 401 failures and verify legacy cache bytes, initialization safety, and session recovery.
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { database } from '.';
|
|
|
|
// Aggregate SQL stays explicit and bound; public input is never used as an SQL
|
|
// identifier. These queries preserve the dashboard response names.
|
|
export const statistics = {
|
|
async totals(date: string) {
|
|
const rows = await database.query(
|
|
`SELECT SUM(run_count) AS total_runs,
|
|
SUM(success_count) AS total_success, SUM(fail_count) AS total_fail,
|
|
SUM(total_time) AS total_time FROM CrontabStats WHERE date=?`,
|
|
[date],
|
|
);
|
|
return rows[0];
|
|
},
|
|
results(date: string, column: 'success_count' | 'fail_count') {
|
|
if (!['success_count', 'fail_count'].includes(column))
|
|
throw new Error('Invalid statistic');
|
|
return database.query(
|
|
`SELECT ref_id,SUM(${column}) AS result_count FROM CrontabStats
|
|
WHERE date=? AND ${column}>0 GROUP BY ref_id ORDER BY result_count DESC,ref_id ASC`,
|
|
[date],
|
|
);
|
|
},
|
|
trend(dates: string[]) {
|
|
if (!dates.length) return Promise.resolve([]);
|
|
return database.query(
|
|
`SELECT date,SUM(run_count) AS total_runs,
|
|
SUM(success_count) AS total_success,SUM(fail_count) AS total_fail FROM CrontabStats
|
|
WHERE date IN (${dates
|
|
.map(() => '?')
|
|
.join(',')}) GROUP BY date ORDER BY date ASC`,
|
|
dates,
|
|
);
|
|
},
|
|
ranking(date: string, metric: 'total_time' | 'run_count') {
|
|
if (!['total_time', 'run_count'].includes(metric))
|
|
throw new Error('Invalid statistic');
|
|
return database.query(
|
|
`SELECT ref_id,SUM(total_time) AS total_time,SUM(run_count) AS run_count,
|
|
SUM(success_count) AS success_count,MAX(max_time) AS max_time FROM CrontabStats
|
|
WHERE date=? AND run_count>0 GROUP BY ref_id ORDER BY SUM(${metric}) DESC LIMIT 5`,
|
|
[date],
|
|
);
|
|
},
|
|
};
|