change ignore fresh updated, do update after merge instead.

This commit is contained in:
pakintada@gmail.com 2024-02-23 16:48:23 +07:00
parent fed315367a
commit ed7810cded
3 changed files with 54 additions and 27 deletions

View file

@ -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]
}

View file

@ -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,7 +504,7 @@ 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
@ -518,7 +520,7 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(file)
encoder.SetIndent("", " ")
// full
err = encoder.Encode(targetRecipe)
err = encoder.Encode(tempRecipe)
// -------------------------------------------------------------
@ -532,7 +534,6 @@ func (rr *RecipeRouter) updateRecipe(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal Error", http.StatusInternalServerError)
return
}
}
// add to commit
err = data.Insert(&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) {

View file

@ -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) {