simplified store filter
This commit is contained in:
parent
05da113148
commit
d328fe652b
1 changed files with 8 additions and 15 deletions
23
scraping.go
23
scraping.go
|
@ -515,25 +515,18 @@ func storeFilterResult(filter *Filter, db *gorm.DB, debug bool) {
|
||||||
if debug {
|
if debug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var previousOutput FilterOutput
|
filterOutputs := make([]FilterOutput, 1)
|
||||||
db.Model(&FilterOutput{}).Order("time desc").Where("watch_id = ? AND name = ?", filter.WatchID, filter.Name).Limit(1).Find(&previousOutput)
|
|
||||||
// TODO fix filter.Name above and parent.name below
|
|
||||||
for _, parent := range filter.Parents {
|
for _, parent := range filter.Parents {
|
||||||
for _, result := range parent.Results {
|
for _, result := range parent.Results {
|
||||||
if previousOutput.WatchID == 0 {
|
filterOutputs = append(filterOutputs, FilterOutput{
|
||||||
previousOutput.Name = parent.Name
|
WatchID: filter.WatchID,
|
||||||
previousOutput.Time = time.Now()
|
Name: filter.Name,
|
||||||
previousOutput.Value = result
|
Time: time.Now(),
|
||||||
previousOutput.WatchID = filter.WatchID
|
Value: result,
|
||||||
db.Create(&previousOutput)
|
})
|
||||||
} else {
|
|
||||||
previousOutput.Time = time.Now()
|
|
||||||
previousOutput.ID = 0
|
|
||||||
previousOutput.Value = result
|
|
||||||
db.Create(&previousOutput)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
db.Create(&filterOutputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFilterResultConditionDiff(filter *Filter, db *gorm.DB) {
|
func getFilterResultConditionDiff(filter *Filter, db *gorm.DB) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue