perf(server): batch achievement updates and eliminate redundant snapshots, writes and JSON round trips

This commit is contained in:
2026-10-06 20:47:33 +08:00
parent c13ff41878
commit b9f1ac4aa6
13 changed files with 813 additions and 79 deletions
+13 -3
View File
@@ -31,15 +31,25 @@ func Encode(code int, proto, key []byte, now int64) ([]byte, error) {
// Notify is plain base64 protobuf in the JSON envelope. The client parses it
// separately after decrypting the response data (NetworkManager.OnAfterResponse).
func EncodeWithNotify(code int, proto, key []byte, now int64, notify []byte) ([]byte, error) {
data, err := cryptox.EncryptBase64Payload(proto, key)
envelope, err := EnvelopeWithNotify(code, proto, key, now, notify)
if err != nil {
return nil, err
}
return json.Marshal(Envelope{
return json.Marshal(envelope)
}
// EnvelopeWithNotify builds the same wire response without an intermediate
// JSON round trip when the caller is assembling a batch.
func EnvelopeWithNotify(code int, proto, key []byte, now int64, notify []byte) (Envelope, error) {
data, err := cryptox.EncryptBase64Payload(proto, key)
if err != nil {
return Envelope{}, err
}
return Envelope{
PacketCode: code, Length: base64.StdEncoding.EncodedLen(len(proto)),
Data: data, ServerNowTime: now,
Notify: base64.StdEncoding.EncodeToString(notify),
})
}, nil
}
type BatchRequest struct {