only save to boltdb if it's a force refresh

This commit is contained in:
Shawn Smith
2016-02-06 14:15:37 +09:00
parent 8d86983517
commit 8b0744ef9d

View File

@@ -48,26 +48,29 @@ func CheckHandler(w http.ResponseWriter, r *http.Request) {
}
w.Write(respBytes)
// write to boltdb
db, err := bolt.Open(DBPath, 0755, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
log.Println("Failed to open bolt database: ", err)
return
}
defer db.Close()
log.Printf("Saving repo %q to cache...", repo)
err = db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(RepoBucket))
if b == nil {
return fmt.Errorf("repo bucket not found")
if forceRefresh {
// write to boltdb
db, err := bolt.Open(DBPath, 0755, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
log.Println("Failed to open bolt database: ", err)
return
}
return b.Put([]byte(repo), respBytes)
})
defer db.Close()
if err != nil {
log.Println("Bolt writing error:", err)
log.Printf("Saving repo %q to cache...", repo)
err = db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(RepoBucket))
if b == nil {
return fmt.Errorf("repo bucket not found")
}
return b.Put([]byte(repo), respBytes)
})
if err != nil {
log.Println("Bolt writing error:", err)
}
}
return
}