mirror of
https://github.com/gojp/goreportcard.git
synced 2026-02-05 20:49:19 +08:00
only write to mongo when it's force refresh
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user