fix: invalidate group settings cache on membership changes

This commit is contained in:
richjohnrambo
2026-09-16 01:03:40 +08:00
parent 139681fadb
commit 9626e8ee7c
5 changed files with 393 additions and 7 deletions
+15 -1
View File
@@ -13,6 +13,7 @@ type testGroupMessageRuntime struct {
seqs map[string]int64
shortStates map[string]bool
deletedPrefixes []string
deletedObjects []string
}
func newTestGroupMessageRuntime() *testGroupMessageRuntime {
@@ -152,7 +153,8 @@ func (r *testGroupMessageRuntime) GetCachedObject(types.TenantID, string, string
return false, nil
}
func (r *testGroupMessageRuntime) DeleteCachedObject(types.TenantID, string, string) error {
func (r *testGroupMessageRuntime) DeleteCachedObject(_ types.TenantID, namespace, id string) error {
r.deletedObjects = append(r.deletedObjects, namespace+":"+id)
return nil
}
@@ -311,3 +313,15 @@ func TestInvalidateGroupMemberPagesUsesTopicKeyPrefix(t *testing.T) {
t.Fatalf("unexpected deleted prefixes: %#v", runtime.deletedPrefixes)
}
}
func TestInvalidateGroupSettingsUsesTopicCacheKey(t *testing.T) {
oldRuntime := groupMsgRuntime
runtime := newTestGroupMessageRuntime()
groupMsgRuntime = runtime
t.Cleanup(func() { groupMsgRuntime = oldRuntime })
invalidateGroupSettings(7, " grpAlpha ")
if len(runtime.deletedObjects) != 1 || runtime.deletedObjects[0] != "group_settings:grpAlpha" {
t.Fatalf("unexpected deleted objects: %#v", runtime.deletedObjects)
}
}