Commit 899573db authored by ale's avatar ale

Implement log minimization

Enforced on the AddLog method.
parent 31a8b034
Pipeline #710 passed with stages
in 1 minute and 27 seconds
......@@ -149,6 +149,8 @@ func (u *userlogDB) AddLog(entry *usermetadb.LogEntry) error {
return err
}
minimizeLogEntry(entry)
tx, err := u.db.Begin()
if err != nil {
return err
......@@ -284,3 +286,21 @@ func (u *userlogDB) Prune() error {
}
return nil
}
var timestampRoundSeconds int64 = 7200
func roundTimestamp(t time.Time, r int64) time.Time {
return time.Unix((t.Unix()/r)*r, 0)
}
// Minimize a log entry, removing all the data that we don't want to
// store (even if it's already missing in the database schema).
func minimizeLogEntry(e *usermetadb.LogEntry) {
// Round timestamps to the nearest even hour.
e.Timestamp = roundTimestamp(e.Timestamp, timestampRoundSeconds)
// Drop fields in DeviceInfo that we don't want.
if e.DeviceInfo != nil {
e.DeviceInfo.RemoteAddr = ""
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment