mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-19 18:56:48 +02:00
cleaned up empty lines + linting
This commit is contained in:
parent
94adf2c9d4
commit
b41d10ec27
3 changed files with 19 additions and 23 deletions
|
@ -91,16 +91,15 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
|
|
||||||
for (let monitorID of monitorIDList) {
|
for (let monitorID of monitorIDList) {
|
||||||
let list;
|
let list;
|
||||||
|
|
||||||
// Try to use aggregated data from stat tables for better performance
|
// Try to use aggregated data from stat tables for better performance
|
||||||
const aggregatedData = await getAggregatedHeartbeatData(monitorID, heartbeatRange);
|
const aggregatedData = await getAggregatedHeartbeatData(monitorID, heartbeatRange);
|
||||||
|
|
||||||
if (aggregatedData) {
|
if (aggregatedData) {
|
||||||
// Use pre-aggregated stat data
|
// Use pre-aggregated stat data
|
||||||
heartbeatList[monitorID] = aggregatedData;
|
heartbeatList[monitorID] = aggregatedData;
|
||||||
} else {
|
} else {
|
||||||
// Fall back to raw heartbeat data (auto mode or no stat data)
|
// Fall back to raw heartbeat data (auto mode or no stat data)
|
||||||
|
|
||||||
if (heartbeatRange === "auto") {
|
if (heartbeatRange === "auto") {
|
||||||
// Auto mode - use original LIMIT 100 logic
|
// Auto mode - use original LIMIT 100 logic
|
||||||
list = await R.getAll(`
|
list = await R.getAll(`
|
||||||
|
@ -116,9 +115,8 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
const hours = parseRangeHours(heartbeatRange);
|
const hours = parseRangeHours(heartbeatRange);
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
date.setHours(date.getHours() - hours);
|
date.setHours(date.getHours() - hours);
|
||||||
const dateFrom = date.toISOString().slice(0, 19).replace('T', ' ');
|
const dateFrom = date.toISOString().slice(0, 19).replace("T", " ");
|
||||||
|
|
||||||
|
|
||||||
list = await R.getAll(`
|
list = await R.getAll(`
|
||||||
SELECT * FROM heartbeat
|
SELECT * FROM heartbeat
|
||||||
WHERE monitor_id = ? AND time >= ?
|
WHERE monitor_id = ? AND time >= ?
|
||||||
|
|
|
@ -14,13 +14,13 @@ function parseRangeHours(range) {
|
||||||
if (!range || range === "auto") {
|
if (!range || range === "auto") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (range.endsWith("h")) {
|
if (range.endsWith("h")) {
|
||||||
return parseInt(range);
|
return parseInt(range);
|
||||||
} else if (range.endsWith("d")) {
|
} else if (range.endsWith("d")) {
|
||||||
return parseInt(range) * 24;
|
return parseInt(range) * 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback
|
// Fallback
|
||||||
return 90 * 24;
|
return 90 * 24;
|
||||||
}
|
}
|
||||||
|
@ -35,26 +35,26 @@ async function getAggregatedHeartbeatData(monitorId, range) {
|
||||||
if (!range || range === "auto") {
|
if (!range || range === "auto") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = dayjs();
|
const now = dayjs();
|
||||||
const hours = parseRangeHours(range);
|
const hours = parseRangeHours(range);
|
||||||
|
|
||||||
if (hours <= 24) {
|
if (hours <= 24) {
|
||||||
// Use hourly stats for ranges up to 24 hours
|
// Use hourly stats for ranges up to 24 hours
|
||||||
const startTime = now.subtract(hours, "hours");
|
const startTime = now.subtract(hours, "hours");
|
||||||
const timestampKey = Math.floor(startTime.valueOf() / (60 * 60 * 1000)); // Convert to seconds
|
const timestampKey = Math.floor(startTime.valueOf() / (60 * 60 * 1000)); // Convert to seconds
|
||||||
|
|
||||||
const stats = await R.getAll(`
|
const stats = await R.getAll(`
|
||||||
SELECT * FROM stat_hourly
|
SELECT * FROM stat_hourly
|
||||||
WHERE monitor_id = ? AND timestamp >= ?
|
WHERE monitor_id = ? AND timestamp >= ?
|
||||||
ORDER BY timestamp ASC
|
ORDER BY timestamp ASC
|
||||||
`, [monitorId, timestampKey]);
|
`, [ monitorId, timestampKey ]);
|
||||||
|
|
||||||
// If no stat data, fall back to raw heartbeat data
|
// If no stat data, fall back to raw heartbeat data
|
||||||
if (stats.length === 0) {
|
if (stats.length === 0) {
|
||||||
return null; // This will trigger fallback in router
|
return null; // This will trigger fallback in router
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert stat data to simplified format for client-side aggregation
|
// Convert stat data to simplified format for client-side aggregation
|
||||||
const result = stats.map(stat => ({
|
const result = stats.map(stat => ({
|
||||||
time: dayjs(stat.timestamp * 1000).format("YYYY-MM-DD HH:mm:ss"),
|
time: dayjs(stat.timestamp * 1000).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
@ -63,25 +63,25 @@ async function getAggregatedHeartbeatData(monitorId, range) {
|
||||||
down: stat.down,
|
down: stat.down,
|
||||||
ping: stat.ping
|
ping: stat.ping
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
// Use daily stats for ranges over 24 hours
|
// Use daily stats for ranges over 24 hours
|
||||||
const days = Math.ceil(hours / 24);
|
const days = Math.ceil(hours / 24);
|
||||||
const startTime = now.subtract(days, "days");
|
const startTime = now.subtract(days, "days");
|
||||||
const timestampKey = Math.floor(startTime.valueOf() / (24 * 60 * 60 * 1000)); // Convert to seconds
|
const timestampKey = Math.floor(startTime.valueOf() / (24 * 60 * 60 * 1000)); // Convert to seconds
|
||||||
|
|
||||||
const stats = await R.getAll(`
|
const stats = await R.getAll(`
|
||||||
SELECT * FROM stat_daily
|
SELECT * FROM stat_daily
|
||||||
WHERE monitor_id = ? AND timestamp >= ?
|
WHERE monitor_id = ? AND timestamp >= ?
|
||||||
ORDER BY timestamp ASC
|
ORDER BY timestamp ASC
|
||||||
`, [monitorId, timestampKey]);
|
`, [ monitorId, timestampKey ]);
|
||||||
|
|
||||||
// If no stat data, fall back to raw heartbeat data
|
// If no stat data, fall back to raw heartbeat data
|
||||||
if (stats.length === 0) {
|
if (stats.length === 0) {
|
||||||
return null; // This will trigger fallback in router
|
return null; // This will trigger fallback in router
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert stat data to simplified format for client-side aggregation
|
// Convert stat data to simplified format for client-side aggregation
|
||||||
const result = stats.map(stat => ({
|
const result = stats.map(stat => ({
|
||||||
time: dayjs(stat.timestamp * 1000).format("YYYY-MM-DD HH:mm:ss"),
|
time: dayjs(stat.timestamp * 1000).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
|
@ -90,7 +90,7 @@ async function getAggregatedHeartbeatData(monitorId, range) {
|
||||||
down: stat.down,
|
down: stat.down,
|
||||||
ping: stat.ping
|
ping: stat.ping
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,4 +98,4 @@ async function getAggregatedHeartbeatData(monitorId, range) {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parseRangeHours,
|
parseRangeHours,
|
||||||
getAggregatedHeartbeatData
|
getAggregatedHeartbeatData
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,7 +99,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
shortBeatList() {
|
shortBeatList() {
|
||||||
|
|
||||||
if (!this.beatList) {
|
if (!this.beatList) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -130,7 +129,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
aggregatedBeatList() {
|
aggregatedBeatList() {
|
||||||
|
|
||||||
if (!this.beatList || this.beatList.length === 0) {
|
if (!this.beatList || this.beatList.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue