mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 05:43:41 +03:00
Fix stale story-unlock and post-evolve weapon state
This commit is contained in:
@@ -294,17 +294,16 @@ func ComputeDelta(before, after *store.UserState, changedTables []string) map[st
|
||||
diff := make(map[string]*pb.DiffData, len(changedTables))
|
||||
for _, table := range changedTables {
|
||||
afterJSON := projectTable(table, *after)
|
||||
updates := afterJSON
|
||||
deleteKeys := "[]"
|
||||
if kf := keyFieldsForTable(table); len(kf) > 0 {
|
||||
beforeJSON := projectTable(table, *before)
|
||||
deleteKeys = ComputeDeleteKeys(
|
||||
parseJSONRecords(beforeJSON),
|
||||
parseJSONRecords(afterJSON),
|
||||
kf,
|
||||
)
|
||||
beforeRecs := parseJSONRecords(projectTable(table, *before))
|
||||
afterRecs := parseJSONRecords(afterJSON)
|
||||
updates = ComputeUpdateRecords(beforeRecs, afterRecs, kf)
|
||||
deleteKeys = ComputeDeleteKeys(beforeRecs, afterRecs, kf)
|
||||
}
|
||||
diff[table] = &pb.DiffData{
|
||||
UpdateRecordsJson: afterJSON,
|
||||
UpdateRecordsJson: updates,
|
||||
DeleteKeysJson: deleteKeys,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package userdata
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
pb "lunar-tear/server/gen/proto"
|
||||
@@ -120,6 +121,34 @@ func ComputeDeleteKeys(oldRecords, newRecords []map[string]any, keyFields []stri
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ComputeUpdateRecords(oldRecords, newRecords []map[string]any, keyFields []string) string {
|
||||
if len(newRecords) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
|
||||
oldByKey := make(map[string]map[string]any, len(oldRecords))
|
||||
for _, r := range oldRecords {
|
||||
oldByKey[compositeKey(r, keyFields)] = r
|
||||
}
|
||||
|
||||
var changed []map[string]any
|
||||
for _, r := range newRecords {
|
||||
prev, exists := oldByKey[compositeKey(r, keyFields)]
|
||||
if !exists || !reflect.DeepEqual(prev, r) {
|
||||
changed = append(changed, r)
|
||||
}
|
||||
}
|
||||
|
||||
if len(changed) == 0 {
|
||||
return "[]"
|
||||
}
|
||||
b, err := json.Marshal(changed)
|
||||
if err != nil {
|
||||
return "[]"
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func compositeKey(record map[string]any, fields []string) string {
|
||||
var sb strings.Builder
|
||||
for i, f := range fields {
|
||||
|
||||
Reference in New Issue
Block a user