mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-07-26 11:38:13 +00:00
Improve DNS metric data retrieval by handling errors gracefully.
Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/ecf19442-1aeb-4010-a943-79973ff53254.jpg
This commit is contained in:
+30
-10
@@ -438,16 +438,36 @@ export class DatabaseStorage implements IStorage {
|
||||
startDate?: Date,
|
||||
endDate?: Date
|
||||
): Promise<DnsMetric[]> {
|
||||
let query = db.select().from(dnsMetrics).where(eq(dnsMetrics.metricType, metricType));
|
||||
|
||||
if (startDate) {
|
||||
query = query.where(sql`${dnsMetrics.timestamp} >= ${startDate}`);
|
||||
try {
|
||||
// Build the conditions array
|
||||
const conditions = [eq(dnsMetrics.metricType, metricType)];
|
||||
|
||||
if (startDate) {
|
||||
conditions.push(sql`${dnsMetrics.timestamp} >= ${startDate}`);
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
conditions.push(sql`${dnsMetrics.timestamp} <= ${endDate}`);
|
||||
}
|
||||
|
||||
// Use a single where with and() to combine all conditions
|
||||
const results = await db.select({
|
||||
id: dnsMetrics.id,
|
||||
domainId: dnsMetrics.domainId,
|
||||
recordId: dnsMetrics.recordId,
|
||||
metricType: dnsMetrics.metricType,
|
||||
value: dnsMetrics.value,
|
||||
tags: dnsMetrics.tags,
|
||||
timestamp: dnsMetrics.timestamp
|
||||
})
|
||||
.from(dnsMetrics)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(dnsMetrics.timestamp));
|
||||
|
||||
return results;
|
||||
} catch (error) {
|
||||
console.error("Error in getDnsMetricsByType:", error);
|
||||
return []; // Return empty array instead of propagating the error
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
query = query.where(sql`${dnsMetrics.timestamp} <= ${endDate}`);
|
||||
}
|
||||
|
||||
return await query.orderBy(desc(dnsMetrics.timestamp));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user