remove comments
This commit is contained in:
1 parent
2b2db2df6f
commit
317d531775
1 file changed
+2
-8
@@ -31,8 +31,8 @@ const dateStringToBucket = (dateString: string): string => {
|
|||||||
export class TimescaleChecksRepository implements IChecksRepository {
|
export class TimescaleChecksRepository implements IChecksRepository {
|
||||||
constructor(private pool: Pool) {}
|
constructor(private pool: Pool) {}
|
||||||
|
|
||||||
// Returns the continuous aggregate table name for the given bucket interval and query type,
|
// Returns correct CA table name for the given bucket interval and query type
|
||||||
// or null if no CA is available (fall back to raw checks table).
|
// Or returns null if no CA is available (fall back to raw checks table).
|
||||||
private getCaTable(bucket: string, type: "uptime" | "hardware" | "pagespeed"): string | null {
|
private getCaTable(bucket: string, type: "uptime" | "hardware" | "pagespeed"): string | null {
|
||||||
if (type === "uptime" && bucket === "1 hour") return "checks_hourly";
|
if (type === "uptime" && bucket === "1 hour") return "checks_hourly";
|
||||||
if (type === "uptime" && bucket === "1 day") return "checks_daily";
|
if (type === "uptime" && bucket === "1 day") return "checks_daily";
|
||||||
@@ -47,7 +47,6 @@ export class TimescaleChecksRepository implements IChecksRepository {
|
|||||||
throw new Error("Failed to create check");
|
throw new Error("Failed to create check");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert child records
|
|
||||||
if (check.disk?.length) {
|
if (check.disk?.length) {
|
||||||
await this.insertDisks(row.id, row.created_at, check.disk);
|
await this.insertDisks(row.id, row.created_at, check.disk);
|
||||||
}
|
}
|
||||||
@@ -221,13 +220,10 @@ export class TimescaleChecksRepository implements IChecksRepository {
|
|||||||
};
|
};
|
||||||
|
|
||||||
deleteOlderThan = async (date: Date): Promise<number> => {
|
deleteOlderThan = async (date: Date): Promise<number> => {
|
||||||
// TimescaleDB drop_chunks is O(1) per chunk, much faster than row-by-row DELETE
|
|
||||||
const result = await this.pool.query(`DELETE FROM checks WHERE created_at < $1`, [date]);
|
const result = await this.pool.query(`DELETE FROM checks WHERE created_at < $1`, [date]);
|
||||||
return result.rowCount ?? 0;
|
return result.rowCount ?? 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Private helpers ---
|
|
||||||
|
|
||||||
private populateChildData = async (checkRows: Record<string, unknown>[]): Promise<Check[]> => {
|
private populateChildData = async (checkRows: Record<string, unknown>[]): Promise<Check[]> => {
|
||||||
if (!checkRows.length) return [];
|
if (!checkRows.length) return [];
|
||||||
|
|
||||||
@@ -702,7 +698,6 @@ export class TimescaleChecksRepository implements IChecksRepository {
|
|||||||
[bucket, monitorId, startDate, endDate]
|
[bucket, monitorId, startDate, endDate]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Batched disk query across all buckets (eliminates N+1)
|
|
||||||
const diskQuery = this.pool.query(
|
const diskQuery = this.pool.query(
|
||||||
`SELECT
|
`SELECT
|
||||||
time_bucket($1::interval, d.check_created_at) AS bucket_date,
|
time_bucket($1::interval, d.check_created_at) AS bucket_date,
|
||||||
@@ -793,7 +788,6 @@ export class TimescaleChecksRepository implements IChecksRepository {
|
|||||||
[bucket, monitorId, startDate, endDate]
|
[bucket, monitorId, startDate, endDate]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Run all 5 queries in parallel
|
|
||||||
const [totalResult, upResult, metricsResult, tempResult, diskResult, netResult] = await Promise.all([
|
const [totalResult, upResult, metricsResult, tempResult, diskResult, netResult] = await Promise.all([
|
||||||
this.pool.query(
|
this.pool.query(
|
||||||
`SELECT COUNT(*)::int AS count FROM checks
|
`SELECT COUNT(*)::int AS count FROM checks
|
||||||
|
|||||||
Reference in new issue
Block a user