|
|
@ -11,8 +11,11 @@ import (
|
|
|
|
"github.com/samonzeweb/godb/adapters/sqlite"
|
|
|
|
"github.com/samonzeweb/godb/adapters/sqlite"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
//nolint:funlen,cyclop
|
|
|
|
// ConvertCache converts files-based cache into the DB-based cache.
|
|
|
|
func (c *Cache) ConvertCache() error {
|
|
|
|
// If reset is true, the DB cache is created from scratch.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//nolint:funlen,cyclop,gocognit
|
|
|
|
|
|
|
|
func (c *Cache) ConvertCache(reset bool) error {
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
dbfile = c.config.Geo.LocationCacheDB
|
|
|
|
dbfile = c.config.Geo.LocationCacheDB
|
|
|
|
tableName = "Location"
|
|
|
|
tableName = "Location"
|
|
|
@ -20,20 +23,24 @@ func (c *Cache) ConvertCache() error {
|
|
|
|
known = map[string]bool{}
|
|
|
|
known = map[string]bool{}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if reset {
|
|
|
|
err := removeDBIfExists(dbfile)
|
|
|
|
err := removeDBIfExists(dbfile)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db, err := godb.Open(sqlite.Adapter, dbfile)
|
|
|
|
db, err := godb.Open(sqlite.Adapter, dbfile)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if reset {
|
|
|
|
err = createTable(db, tableName)
|
|
|
|
err = createTable(db, tableName)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.Println("listing cache entries...")
|
|
|
|
log.Println("listing cache entries...")
|
|
|
|
files, err := filepath.Glob(filepath.Join(cacheFiles, "*"))
|
|
|
|
files, err := filepath.Glob(filepath.Join(cacheFiles, "*"))
|
|
|
|