mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-09 23:24:07 -08:00
afterLogin change to non blocking
This commit is contained in:
parent
50f300dd28
commit
46cb955172
|
@ -150,7 +150,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||||
if (user) {
|
if (user) {
|
||||||
debug("afterLogin")
|
debug("afterLogin")
|
||||||
|
|
||||||
await afterLogin(socket, user)
|
afterLogin(socket, user)
|
||||||
|
|
||||||
debug("afterLogin ok")
|
debug("afterLogin ok")
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||||
let user = await login(data.username, data.password)
|
let user = await login(data.username, data.password)
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
await afterLogin(socket, user)
|
afterLogin(socket, user)
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
|
@ -561,7 +561,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||||
debug("check auto login")
|
debug("check auto login")
|
||||||
if (await setting("disableAuth")) {
|
if (await setting("disableAuth")) {
|
||||||
console.log("Disabled Auth: auto login to admin")
|
console.log("Disabled Auth: auto login to admin")
|
||||||
await afterLogin(socket, await R.findOne("user"))
|
afterLogin(socket, await R.findOne("user"))
|
||||||
socket.emit("autoLogin")
|
socket.emit("autoLogin")
|
||||||
} else {
|
} else {
|
||||||
debug("need auth")
|
debug("need auth")
|
||||||
|
@ -621,6 +621,8 @@ async function sendMonitorList(socket) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendNotificationList(socket) {
|
async function sendNotificationList(socket) {
|
||||||
|
const timeLogger = new TimeLogger();
|
||||||
|
|
||||||
let result = [];
|
let result = [];
|
||||||
let list = await R.find("notification", " user_id = ? ", [
|
let list = await R.find("notification", " user_id = ? ", [
|
||||||
socket.userID,
|
socket.userID,
|
||||||
|
@ -631,6 +633,9 @@ async function sendNotificationList(socket) {
|
||||||
}
|
}
|
||||||
|
|
||||||
io.to(socket.userID).emit("notificationList", result)
|
io.to(socket.userID).emit("notificationList", result)
|
||||||
|
|
||||||
|
timeLogger.print("Send Notification List");
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,24 +644,27 @@ async function afterLogin(socket, user) {
|
||||||
socket.join(user.id)
|
socket.join(user.id)
|
||||||
|
|
||||||
let monitorList = await sendMonitorList(socket)
|
let monitorList = await sendMonitorList(socket)
|
||||||
|
|
||||||
sendNotificationList(socket)
|
sendNotificationList(socket)
|
||||||
|
|
||||||
// Delay a bit, so that it let the main page to query the data first, since SQLite can process one sql at the same time only.
|
await sleep(500);
|
||||||
// For example, query the edit data first.
|
|
||||||
setTimeout(async () => {
|
for (let monitorID in monitorList) {
|
||||||
for (let monitorID in monitorList) {
|
await sendHeartbeatList(socket, monitorID);
|
||||||
sendHeartbeatList(socket, monitorID);
|
}
|
||||||
sendImportantHeartbeatList(socket, monitorID);
|
|
||||||
Monitor.sendStats(io, monitorID, user.id)
|
for (let monitorID in monitorList) {
|
||||||
}
|
await sendImportantHeartbeatList(socket, monitorID);
|
||||||
}, 500);
|
}
|
||||||
|
|
||||||
|
for (let monitorID in monitorList) {
|
||||||
|
await Monitor.sendStats(io, monitorID, user.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMonitorJSONList(userID) {
|
async function getMonitorJSONList(userID) {
|
||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
let monitorList = await R.find("monitor", " user_id = ? ", [
|
let monitorList = await R.find("monitor", " user_id = ? ORDER BY weight DESC, name", [
|
||||||
userID,
|
userID,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@ -786,6 +794,8 @@ async function sendHeartbeatList(socket, monitorID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit("heartbeatList", monitorID, result)
|
socket.emit("heartbeatList", monitorID, result)
|
||||||
|
|
||||||
|
timeLogger.print(`[Monitor: ${monitorID}] sendHeartbeatList`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendImportantHeartbeatList(socket, monitorID) {
|
async function sendImportantHeartbeatList(socket, monitorID) {
|
||||||
|
|
Loading…
Reference in a new issue