change ignore fresh updated, do update after merge instead.
This commit is contained in:
parent
fed315367a
commit
ed7810cded
3 changed files with 54 additions and 27 deletions
|
|
@ -221,6 +221,16 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
if currentConfig != requestedConfig {
|
||||
d.taoLogger.Log.Debug("GetRecipe", zap.Any("ActualFileNotMatch", "Skip this!"))
|
||||
} else {
|
||||
|
||||
// detect patches, return original
|
||||
var cached_original_recipe models.Recipe
|
||||
err := d.redisClient.GetKeyTo(filename, &cached_original_recipe)
|
||||
|
||||
if err == nil && d.redisClient.HealthCheck() == nil {
|
||||
d.taoLogger.Log.Debug("GetRecipe.NoReturnUpdated", zap.Any("target", filename))
|
||||
return &cached_original_recipe
|
||||
}
|
||||
|
||||
// if equal, OK
|
||||
return d.CurrentRecipe[countryID]
|
||||
}
|
||||
|
|
@ -239,6 +249,19 @@ func (d *Data) GetRecipe(countryID, filename string) *models.Recipe {
|
|||
if currentConfig != requestedConfig {
|
||||
d.taoLogger.Log.Debug("GetRecipe", zap.Any("InvalidOnStored", "Skip this!"))
|
||||
} else {
|
||||
|
||||
// detect patches, return original
|
||||
|
||||
var cached_original_recipe models.Recipe
|
||||
err := d.redisClient.GetKeyTo(filename, &cached_original_recipe)
|
||||
|
||||
if err == nil && d.redisClient.HealthCheck() == nil {
|
||||
d.taoLogger.Log.Debug("GetRecipe.NoReturnUpdated", zap.Any("target", filename))
|
||||
return &cached_original_recipe
|
||||
}
|
||||
|
||||
d.taoLogger.Log.Debug("GetRecipe.ReturnDefault", zap.Any("error_cache_recipe", err))
|
||||
|
||||
// if equal, OK
|
||||
return recipe.Recipe[countryID]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -448,6 +448,8 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
|||
// Apply changes
|
||||
tempRecipe := models.Recipe01{}
|
||||
tempRecipe = tempRecipe.FromMap(changeMap)
|
||||
|
||||
// Disable temp! Was updated the master by patch. Too fast
|
||||
rr.data.SetValuesToRecipe(targetRecipe.Recipe01, tempRecipe)
|
||||
|
||||
rr.taoLogger.Log.Debug("ApplyChange", zap.Any("status", "passed"))
|
||||
|
|
@ -502,36 +504,35 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
// this following codes do need users to pass update to each other
|
||||
// otherwise, the changes will diverge
|
||||
// this following codes do need users to pass update to each other
|
||||
// otherwise, the changes will diverge
|
||||
|
||||
file, _ := os.Create(temp_file_name)
|
||||
if err != nil {
|
||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when tried to create file")))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
file, _ := os.Create(temp_file_name)
|
||||
if err != nil {
|
||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when tried to create file")))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// write to local if cannot connect
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ")
|
||||
// full
|
||||
err = encoder.Encode(targetRecipe)
|
||||
// write to local if cannot connect
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ")
|
||||
// full
|
||||
err = encoder.Encode(tempRecipe)
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// -------------------------------------------------------------
|
||||
|
||||
// partial
|
||||
// err = encoder.Encode(changes)
|
||||
// partial
|
||||
// err = encoder.Encode(changes)
|
||||
|
||||
// put changes to redis
|
||||
// put changes to redis
|
||||
|
||||
if err != nil {
|
||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when write file")))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
rr.taoLogger.Log.Error("RecipeRouter.UpdateRecipe", zap.Error(errors.WithMessage(err, "Error when write file")))
|
||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// add to commit
|
||||
|
|
@ -624,7 +625,7 @@ func (rr *RecipeRouter) getSavedAsPatches(w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("targetPatchOf", countryID+"."+filename+":patchList"), zap.Any("patchList", patchList))
|
||||
// rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("targetPatchOf", countryID+"."+filename+":patchList"), zap.Any("patchList", patchList))
|
||||
|
||||
// find patch content from patch list
|
||||
keys, err := rr.cache_db.KeyList()
|
||||
|
|
@ -662,7 +663,11 @@ func (rr *RecipeRouter) getSavedAsPatches(w http.ResponseWriter, r *http.Request
|
|||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(patchMap)
|
||||
|
||||
rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("patchMap", patchMap))
|
||||
// The above code is using the Zap logging library in Go to log a debug message with two fields. The
|
||||
// first field is "targetPatchOf" with the value of countryID + "." + filename + ":patchList", and the
|
||||
// second field is "patchList" with the value of the variable patchList. This log message is related
|
||||
// to the "RecipeRouter.getSavedAsPatches" method.
|
||||
// rr.taoLogger.Log.Debug("RecipeRouter.getSavedAsPatches", zap.Any("patchMap", patchMap))
|
||||
}
|
||||
|
||||
func (rr *RecipeRouter) getToppings(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package routers
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/services/logger"
|
||||
|
|
@ -28,7 +27,7 @@ func NewToppingRouter(data *data.Data, taoLogger *logger.TaoLogger) *ToppingRout
|
|||
func (tr *ToppingRouter) Route(r chi.Router) {
|
||||
|
||||
// check incoming request
|
||||
fmt.Println("topping router", r.Routes())
|
||||
// fmt.Println("topping router", r.Routes())
|
||||
|
||||
r.Route("/toppover", func(r chi.Router) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue