mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-24 20:45:57 +00:00
For multiple tags with same name, updates the oldest one. (#704)
This commit is contained in:
parent
a2f1d61d31
commit
baa746c662
1 changed files with 14 additions and 13 deletions
|
@ -43,35 +43,36 @@ router.get("/api/push/:pushToken", async (request, response) => {
|
||||||
const tagKeys = Object.keys(requestTags)
|
const tagKeys = Object.keys(requestTags)
|
||||||
if (tagKeys.length > 0) {
|
if (tagKeys.length > 0) {
|
||||||
// Request has additional tags. Fetch all tags for this monitor.
|
// Request has additional tags. Fetch all tags for this monitor.
|
||||||
const dbTags = await trx.getAll("SELECT tag.id, tag.name FROM tag JOIN monitor_tag ON monitor_tag.tag_id = tag.id AND monitor_tag.monitor_id = ?", [monitor.id]);
|
// For multiple tags with same name, get the oldest one.
|
||||||
|
const monitorTags = await trx.getAll("SELECT tag.name, MIN(monitor_tag.id) id FROM monitor_tag JOIN tag ON tag.id = monitor_tag.tag_id AND monitor_tag.monitor_id = ? GROUP BY tag.name ORDER BY 1", [monitor.id]);
|
||||||
|
|
||||||
// Update monitor_tag, ignoring non-existing request tags.
|
// Update monitor_tag, ignoring non-existing request tags.
|
||||||
dbTags
|
monitorTags
|
||||||
.filter(tag => tagKeys.includes(tag.name))
|
.filter(mt => tagKeys.includes(mt.name))
|
||||||
.forEach(async tag => {
|
.forEach(async mt => {
|
||||||
const tagValue = requestTags[tag.name];
|
const tagValue = requestTags[mt.name];
|
||||||
|
|
||||||
await trx.exec("UPDATE monitor_tag SET value = ? WHERE tag_id = ? AND monitor_id = ?", [
|
await trx.exec("UPDATE monitor_tag SET value = ? WHERE id = ?", [
|
||||||
tagValue,
|
tagValue,
|
||||||
tag.id,
|
mt.id
|
||||||
monitor.id,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// FixMe: Not working. What to emit here?
|
// FixMe: Not working. What to emit here?
|
||||||
io.to(monitor.user_id).emit("addMonitorTag", tag.id, monitor.id, tagValue);
|
io.to(monitor.user_id).emit("addMonitorTag", mt.id, monitor.id, tagValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixMe: Bean returned by trx.dispense() has no .toJSON() method (!?).
|
|
||||||
let status = UP;
|
let status = UP;
|
||||||
if (monitor.isUpsideDown()) {
|
// FixMe: monitor.isUpsideDown is not a function (?)
|
||||||
status = flipStatus(status);
|
//if (monitor.isUpsideDown()) {
|
||||||
}
|
// status = flipStatus(status);
|
||||||
|
//}
|
||||||
|
|
||||||
let isFirstBeat = true;
|
let isFirstBeat = true;
|
||||||
let previousStatus = status;
|
let previousStatus = status;
|
||||||
let duration = 0;
|
let duration = 0;
|
||||||
|
|
||||||
|
// FixMe: Bean returned by trx.dispense() has no .toJSON() method (!?).
|
||||||
let bean = R.dispense("heartbeat"); // Should be trx.dispense();
|
let bean = R.dispense("heartbeat"); // Should be trx.dispense();
|
||||||
bean.time = R.isoDateTime(dayjs.utc());
|
bean.time = R.isoDateTime(dayjs.utc());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue