added db prune job, remove data that doesn't change
This commit is contained in:
parent
3cf87150a7
commit
2b410431b4
2 changed files with 30 additions and 2 deletions
29
main.go
29
main.go
|
@ -144,6 +144,11 @@ func (web *Web) initCronJobs() {
|
|||
log.Println("Started CronJob for WatchID", cronFilter.WatchID, "with schedule:", cronFilter.Var1)
|
||||
web.cronWatch[cronFilter.ID] = entryID
|
||||
}
|
||||
if viper.IsSet("database.prune") {
|
||||
pruneSchedule := viper.GetString("database.prune")
|
||||
web.cron.AddFunc(pruneSchedule, web.pruneDB)
|
||||
log.Println("Started DB prune cronjob:", pruneSchedule)
|
||||
}
|
||||
web.cron.Start()
|
||||
}
|
||||
|
||||
|
@ -157,6 +162,30 @@ func (web *Web) initNotifiers() {
|
|||
}
|
||||
}
|
||||
|
||||
func (web *Web) pruneDB() {
|
||||
log.Println("Starting database pruning")
|
||||
var storeNames []string
|
||||
web.db.Model(&FilterOutput{}).Distinct().Pluck("name", &storeNames)
|
||||
for _, storeName := range storeNames {
|
||||
log.Println("Pruning:", storeName)
|
||||
var values []FilterOutput
|
||||
web.db.Model(&FilterOutput{}).Order("time asc").Find(&values, fmt.Sprintf("name = '%s'", storeName))
|
||||
IDs := make([]uint, 0, len(values))
|
||||
for i := range values {
|
||||
if i > len(values)-3 {
|
||||
break
|
||||
}
|
||||
a := values[i]
|
||||
b := values[i+1]
|
||||
c := values[i+2]
|
||||
if a.Value == b.Value && b.Value == c.Value {
|
||||
IDs = append(IDs, b.ID)
|
||||
}
|
||||
}
|
||||
web.db.Delete(&FilterOutput{}, IDs)
|
||||
}
|
||||
}
|
||||
|
||||
func (web *Web) notify(notifierKey string, message string) {
|
||||
if notifierKey == "All" {
|
||||
for _, notifier := range web.notifiers {
|
||||
|
|
3
todo.md
3
todo.md
|
@ -9,5 +9,4 @@
|
|||
- etch?
|
||||
- trusted proxies in conf?
|
||||
- log things to db for cron runs
|
||||
- comments
|
||||
- db prune job
|
||||
- comments
|
Loading…
Add table
Reference in a new issue