only write to mongo when it's force refresh

This commit is contained in:
shawnps
2015-02-08 13:56:27 -08:00
parent f4ac915aab
commit d62962fb2b

View File

@@ -31,16 +31,19 @@ func CheckHandler(w http.ResponseWriter, r *http.Request) {
}
w.Write(b)
// write to mongo
db := db.Mongo{URL: mongoURL, Database: mongoDatabase, CollectionName: mongoCollection}
coll, err := db.Collection()
if err != nil {
log.Println("Failed to get mongo collection: ", err)
} else {
log.Println("Writing to mongo...")
_, err := coll.Upsert(bson.M{"repo": repo}, resp)
if forceRefresh {
// write to mongo
db := db.Mongo{URL: mongoURL, Database: mongoDatabase, CollectionName: mongoCollection}
coll, err := db.Collection()
if err != nil {
log.Println("Failed to get mongo collection: ", err)
return
}
log.Printf("Upserting repo %s...", repo)
_, err = coll.Upsert(bson.M{"repo": repo}, resp)
if err != nil {
log.Println("Mongo writing error:", err)
return
}
}
}