* refactor: move code to loadFilters()
This commit is contained in:
parent
b4732c83c5
commit
61b1a30aa1
20
app.go
20
app.go
|
@ -12,7 +12,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/gobuffalo/packr"
|
"github.com/gobuffalo/packr"
|
||||||
|
@ -101,24 +100,7 @@ func run(args options) {
|
||||||
config.BindPort = args.bindPort
|
config.BindPort = args.bindPort
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load filters from the disk
|
loadFilters()
|
||||||
// And if any filter has zero ID, assign a new one
|
|
||||||
for i := range config.Filters {
|
|
||||||
filter := &config.Filters[i] // otherwise we're operating on a copy
|
|
||||||
if filter.ID == 0 {
|
|
||||||
filter.ID = assignUniqueFilterID()
|
|
||||||
}
|
|
||||||
err = filter.load()
|
|
||||||
if err != nil {
|
|
||||||
// This is okay for the first start, the filter will be loaded later
|
|
||||||
log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err)
|
|
||||||
// clear LastUpdated so it gets fetched right away
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(filter.Rules) == 0 {
|
|
||||||
filter.LastUpdated = time.Time{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the updated config
|
// Save the updated config
|
||||||
err = config.write()
|
err = config.write()
|
||||||
|
|
21
filter.go
21
filter.go
|
@ -44,6 +44,27 @@ func userFilter() filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load filters from the disk
|
||||||
|
// And if any filter has zero ID, assign a new one
|
||||||
|
func loadFilters() {
|
||||||
|
for i := range config.Filters {
|
||||||
|
filter := &config.Filters[i] // otherwise we're operating on a copy
|
||||||
|
if filter.ID == 0 {
|
||||||
|
filter.ID = assignUniqueFilterID()
|
||||||
|
}
|
||||||
|
err := filter.load()
|
||||||
|
if err != nil {
|
||||||
|
// This is okay for the first start, the filter will be loaded later
|
||||||
|
log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err)
|
||||||
|
// clear LastUpdated so it gets fetched right away
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(filter.Rules) == 0 {
|
||||||
|
filter.LastUpdated = time.Time{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func deduplicateFilters() {
|
func deduplicateFilters() {
|
||||||
// Deduplicate filters
|
// Deduplicate filters
|
||||||
i := 0 // output index, used for deletion later
|
i := 0 // output index, used for deletion later
|
||||||
|
|
Loading…
Reference in New Issue