History bug fixes
This commit is contained in:
parent
316a02fa2f
commit
6b77b66d4e
4 changed files with 9 additions and 15 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
function getHistHTML(hist) {
|
function getHistHTML(hist) {
|
||||||
|
|
||||||
hist = sortHistByDate(hist);
|
|
||||||
|
|
||||||
let html = '', col, title;
|
let html = '', col, title;
|
||||||
|
|
||||||
for (let h of hist) {
|
for (let h of hist) {
|
||||||
|
|
@ -23,7 +21,7 @@ function getHistHTML(hist) {
|
||||||
|
|
||||||
function sortHistByDate(hist) {
|
function sortHistByDate(hist) {
|
||||||
|
|
||||||
hist.sort((a, b) => (a.Date > b.Date));
|
hist.sort((a, b) => (a.Date < b.Date ? 1 : -1));
|
||||||
|
|
||||||
return hist;
|
return hist;
|
||||||
}
|
}
|
||||||
|
|
@ -26,6 +26,8 @@ async function loadHistory() {
|
||||||
for (let a of addrsArray) {
|
for (let a of addrsArray) {
|
||||||
url = '/api/history/'+a.Mac;
|
url = '/api/history/'+a.Mac;
|
||||||
hist = await (await fetch(url)).json();
|
hist = await (await fetch(url)).json();
|
||||||
|
hist = sortHistByDate(hist);
|
||||||
|
|
||||||
if (show > 0) {
|
if (show > 0) {
|
||||||
hist = hist.slice(0, show);
|
hist = hist.slice(0, show);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ async function loadHistory(m) {
|
||||||
const url = '/api/history/'+mac;
|
const url = '/api/history/'+mac;
|
||||||
|
|
||||||
let hist = await (await fetch(url)).json();
|
let hist = await (await fetch(url)).json();
|
||||||
|
hist = sortHistByDate(hist);
|
||||||
if (show > 0) {
|
if (show > 0) {
|
||||||
hist = hist.slice(0, show);
|
hist = hist.slice(0, show);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ func trimHistory() {
|
||||||
nowMinus := now.Add(-time.Duration(hours) * time.Hour)
|
nowMinus := now.Add(-time.Duration(hours) * time.Hour)
|
||||||
|
|
||||||
history := histHosts
|
history := histHosts
|
||||||
|
|
||||||
if appConfig.HistInDB {
|
if appConfig.HistInDB {
|
||||||
history = db.Select("history")
|
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"))
|
slog.Info("Removing all History before", "date", nowMinus.Format("2006-01-02 15:04:05"))
|
||||||
|
|
||||||
n := 0
|
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)
|
date, _ := time.Parse("2006-01-02 15:04:05", hist.Date)
|
||||||
|
|
||||||
if date.Before(nowMinus) {
|
if date.Before(nowMinus) {
|
||||||
n = n + 1
|
n = n + 1
|
||||||
if appConfig.HistInDB {
|
if appConfig.HistInDB {
|
||||||
db.Delete("history", hist.ID)
|
db.Delete("history", hist.ID)
|
||||||
} else {
|
|
||||||
historyDel(i)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
histHosts = append(histHosts, hist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Removed records from History", "n", n)
|
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]
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue