History bug fixes

This commit is contained in:
aceberg 2024-08-30 01:49:46 +07:00
parent 316a02fa2f
commit 6b77b66d4e
4 changed files with 9 additions and 15 deletions

View file

@ -1,8 +1,6 @@
function getHistHTML(hist) {
hist = sortHistByDate(hist);
let html = '', col, title;
for (let h of hist) {
@ -23,7 +21,7 @@ function getHistHTML(hist) {
function sortHistByDate(hist) {
hist.sort((a, b) => (a.Date > b.Date));
hist.sort((a, b) => (a.Date < b.Date ? 1 : -1));
return hist;
}

View file

@ -26,6 +26,8 @@ async function loadHistory() {
for (let a of addrsArray) {
url = '/api/history/'+a.Mac;
hist = await (await fetch(url)).json();
hist = sortHistByDate(hist);
if (show > 0) {
hist = hist.slice(0, show);
}

View file

@ -21,6 +21,7 @@ async function loadHistory(m) {
const url = '/api/history/'+mac;
let hist = await (await fetch(url)).json();
hist = sortHistByDate(hist);
if (show > 0) {
hist = hist.slice(0, show);
}

View file

@ -26,6 +26,7 @@ func trimHistory() {
nowMinus := now.Add(-time.Duration(hours) * time.Hour)
history := histHosts
if appConfig.HistInDB {
history = db.Select("history")
}
@ -33,27 +34,19 @@ func trimHistory() {
slog.Info("Removing all History before", "date", nowMinus.Format("2006-01-02 15:04:05"))
n := 0
for i, hist := range history {
histHosts = []models.Host{}
for _, hist := range history {
date, _ := time.Parse("2006-01-02 15:04:05", hist.Date)
if date.Before(nowMinus) {
n = n + 1
if appConfig.HistInDB {
db.Delete("history", hist.ID)
} else {
historyDel(i)
}
} else {
histHosts = append(histHosts, hist)
}
}
slog.Info("Removed records from History", "n", n)
}
func historyDel(i int) {
l := len(histHosts)
histHosts[i] = histHosts[l-1]
histHosts[l-1] = models.Host{}
histHosts = histHosts[:l-1]
}