mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-09 07:13:45 +08:00
cache last heartbeat list in memory
This commit is contained in:
@@ -283,8 +283,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||
|
||||
bean.import(monitor)
|
||||
bean.user_id = socket.userID
|
||||
await R.store(bean)
|
||||
|
||||
await R.store(bean);
|
||||
await updateMonitorNotification(bean.id, notificationIDList)
|
||||
|
||||
await startMonitor(socket.userID, bean.id);
|
||||
@@ -427,7 +426,6 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||
let monitor = userMonitorList.getMonitor(socket.userID, monitorID);
|
||||
|
||||
if (monitor) {
|
||||
monitor.stop();
|
||||
userMonitorList.delete(socket.userID, monitorID);
|
||||
}
|
||||
|
||||
@@ -678,7 +676,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||
});
|
||||
|
||||
console.log("Starting All Monitors");
|
||||
await startMonitors();
|
||||
await initMonitors();
|
||||
|
||||
console.log("Init the server");
|
||||
|
||||
@@ -818,24 +816,18 @@ async function startMonitor(userID, monitorID) {
|
||||
|
||||
let monitor = await R.findOne("monitor", " id = ? ", [
|
||||
monitorID,
|
||||
])
|
||||
|
||||
let oldMonitor = userMonitorList.getMonitor(userID, monitorID);
|
||||
|
||||
if (oldMonitor) {
|
||||
oldMonitor.stop();
|
||||
}
|
||||
]);
|
||||
|
||||
userMonitorList.add(userID, monitor);
|
||||
monitor.start(io)
|
||||
}
|
||||
|
||||
async function restartMonitor(userID, monitorID) {
|
||||
return await startMonitor(userID, monitorID)
|
||||
return await startMonitor(userID, monitorID);
|
||||
}
|
||||
|
||||
async function pauseMonitor(userID, monitorID) {
|
||||
await checkOwner(userID, monitorID)
|
||||
await checkOwner(userID, monitorID);
|
||||
|
||||
console.log(`Pause Monitor: ${monitorID} User ID: ${userID}`)
|
||||
|
||||
@@ -847,6 +839,7 @@ async function pauseMonitor(userID, monitorID) {
|
||||
let monitor = userMonitorList.getMonitor(userID, monitorID);
|
||||
|
||||
if (monitor) {
|
||||
monitor.active = 0;
|
||||
monitor.stop();
|
||||
}
|
||||
}
|
||||
@@ -854,14 +847,21 @@ async function pauseMonitor(userID, monitorID) {
|
||||
/**
|
||||
* Resume active monitors
|
||||
*/
|
||||
async function startMonitors() {
|
||||
let list = await R.find("monitor", " active = 1 ");
|
||||
async function initMonitors() {
|
||||
// Init all monitors
|
||||
let list = await R.find("monitor");
|
||||
let activeList = [];
|
||||
|
||||
for (let monitor of list) {
|
||||
userMonitorList.add(monitor.user_id, monitor);
|
||||
|
||||
if (monitor.active) {
|
||||
activeList.push(monitor);
|
||||
}
|
||||
}
|
||||
|
||||
delayStartMonitors(list);
|
||||
// Start active monitors only
|
||||
delayStartMonitors(activeList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user