mirror of
https://github.com/chubin/wttr.in
synced 2025-01-25 18:24:59 +00:00
Skip existing entries in db when converting
This commit is contained in:
parent
38e2ddd69b
commit
ecc9479719
1 changed files with 19 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
package location
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -14,7 +16,7 @@ import (
|
|||
// ConvertCache converts files-based cache into the DB-based cache.
|
||||
// If reset is true, the DB cache is created from scratch.
|
||||
//
|
||||
//nolint:funlen,cyclop,gocognit
|
||||
//nolint:funlen,cyclop
|
||||
func (c *Cache) ConvertCache(reset bool) error {
|
||||
var (
|
||||
dbfile = c.config.Geo.LocationCacheDB
|
||||
|
@ -60,12 +62,28 @@ func (c *Cache) ConvertCache(reset bool) error {
|
|||
continue
|
||||
}
|
||||
|
||||
// Skip too long location names.
|
||||
if len(loc.Name) > 25 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip duplicates.
|
||||
if known[loc.Name] {
|
||||
log.Println("skipping", loc.Name)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
singleLocation := Location{}
|
||||
err = db.Select(&singleLocation).
|
||||
Where("name = ?", loc.Name).
|
||||
Do()
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
log.Println("found in db:", loc.Name)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
known[loc.Name] = true
|
||||
|
||||
// Skip some invalid names.
|
||||
|
|
Loading…
Reference in a new issue