mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-23 12:43:48 -04:00
(admin) hopefully decrease peak memory usage of /admin/stats/user-charts/:locale by streaming rows
This commit is contained in:
parent
1a73ddf760
commit
7c25397a9f
@ -6,6 +6,7 @@ const __dirname = new URL('.', import.meta.url).pathname;
|
|||||||
export type SQLQuery = sqlite.ISqlite.SqlType;
|
export type SQLQuery = sqlite.ISqlite.SqlType;
|
||||||
export interface Database {
|
export interface Database {
|
||||||
get<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T | undefined>;
|
get<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T | undefined>;
|
||||||
|
each<T = unknown>(sql: SQLQuery, callback: (err: unknown, row: T) => void): Promise<number>;
|
||||||
all<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T[]>;
|
all<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T[]>;
|
||||||
close(): Promise<void>;
|
close(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,11 @@ export class LazyDatabase implements Database {
|
|||||||
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.get(sql, ...args));
|
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.get(sql, ...args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async each<T = unknown>(sql: SQLQuery, callback: (err: unknown, row: T) => void): Promise<number> {
|
||||||
|
await this.init();
|
||||||
|
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.each(sql, callback));
|
||||||
|
}
|
||||||
|
|
||||||
async all<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T[]> {
|
async all<T = unknown>(sql: SQLQuery, ...args: unknown[]): Promise<T[]> {
|
||||||
await this.init();
|
await this.init();
|
||||||
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.all(sql, ...args));
|
return Sentry.startSpan(this.buildSpanOptions(sql), () => this.db!.all(sql, ...args));
|
||||||
|
@ -224,10 +224,10 @@ router.get('/admin/stats/users-chart/:locale', handleErrorAsync(async (req, res)
|
|||||||
.padStart(2, '0')}`;
|
.padStart(2, '0')}`;
|
||||||
|
|
||||||
const stats = {};
|
const stats = {};
|
||||||
for (const { id, users } of await req.db.all(SQL`SELECT id, users FROM stats WHERE locale = ${req.params.locale} ORDER BY id ASC`)) {
|
await req.db.each(SQL`SELECT id, users FROM stats WHERE locale = ${req.params.locale} ORDER BY id ASC`, (_err, { id, users }) => {
|
||||||
const date = formatDate(new Date(decodeTime(id)));
|
const date = formatDate(new Date(decodeTime(id)));
|
||||||
stats[date] = users; // overwrite with the latest one for the day
|
stats[date] = users; // overwrite with the latest one for the day
|
||||||
}
|
});
|
||||||
|
|
||||||
const incrementsChart = {};
|
const incrementsChart = {};
|
||||||
let prevUsers = null;
|
let prevUsers = null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user