mirror of
https://github.com/hamburghammer/gsave.git
synced 2025-03-15 02:25:55 +01:00
Fix db returning not the newst stats
Getting stats for a host returned allways the oldest item. Now inserting an item stores it at the beginning of the list -> without changing the getting stategy it will now return the newst item.
This commit is contained in:
parent
131a71620d
commit
6d9049820f
1 changed files with 9 additions and 1 deletions
|
@ -88,10 +88,18 @@ func (db *InMemoryDB) InsertStats(hostname string, stats Stats) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
host.Stats = append(host.Stats, stats)
|
||||
host.Stats = db.insertAtBeginning(host.Stats, stats)
|
||||
host.HostInfo.DataPoints++
|
||||
host.HostInfo.LastInsert = time.Now()
|
||||
|
||||
db.storage[hostname] = host
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *InMemoryDB) insertAtBeginning(stats []Stats, stat Stats) []Stats {
|
||||
stats = append(stats, Stats{})
|
||||
copy(stats[1:], stats)
|
||||
stats[0] = stat
|
||||
|
||||
return stats
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue