mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
Root cause: writeAccountIDs unconditionally SET every account payload and metadata record on each scheduler refresh. After 0.2.26 stopped embedding expanded group objects the payload is smaller, but refreshes driven by snapshots or account updates still rewrote all keys even when their content was identical, amplifying AOF and replication traffic when several instances share one Redis. Change: read the previous full and metadata payloads with one chunked MGET per write chunk and compare bytes before writing. Only payloads that changed are SET; unchanged accounts are still returned in the account ID list so bucket membership is unchanged. Platform revisions advance only when a payload was actually written and stay in the last writing chunk, after all metadata writes. The fallback path used when the read fails keeps the original unconditional write and SET ... GET platform-change detection (fail-open). Redis remains the source of truth; no in-process caching is added. Tests: new unit tests cover repeated identical writes issuing no SET and no revision, changed payloads being rewritten, per-chunk skipping, platform changes still advancing the global revision, and the MGET-failure fallback. Existing scheduler cache revision tests were updated for the read-first write layout. Validated with go build ./..., go test -tags=unit ./internal/repository/, and gofmt.