fix unread cache invalidation for forwarded messages

This commit is contained in:
richjohnrambo
2026-09-24 16:37:05 +08:00
parent f952249dc3
commit d41956019a
2 changed files with 47 additions and 0 deletions
+19
View File
@@ -1538,6 +1538,10 @@ func (subsMapper) Get(tenantID types.TenantID, topic string, user types.Uid, kee
// Update values of topic's subscriptions.
func (subsMapper) Update(tenantID types.TenantID, topic string, user types.Uid, update map[string]any) error {
if update == nil {
update = map[string]any{}
}
invalidateUnread := subscriptionUpdateAffectsUnread(update)
update["UpdatedAt"] = types.TimeNow()
tenantAdp, err := tenantBusinessAdapter(tenantID)
if err != nil {
@@ -1547,6 +1551,9 @@ func (subsMapper) Update(tenantID types.TenantID, topic string, user types.Uid,
return err
}
invalidateSubscriptionCache(tenantID, topic, user)
if invalidateUnread {
DeleteCachedUserUnreadCount(tenantID, user)
}
return nil
}
@@ -1561,9 +1568,20 @@ func (subsMapper) Delete(tenantID types.TenantID, topic string, user types.Uid)
return err
}
invalidateSubscriptionCache(tenantID, topic, user)
DeleteCachedUserUnreadCount(tenantID, user)
return nil
}
func subscriptionUpdateAffectsUnread(update map[string]any) bool {
for key := range update {
switch key {
case "ReadSeqId", "DelId", "ModeWant", "ModeGiven", "DeletedAt":
return true
}
}
return false
}
func subscriptionCacheID(topic string, user types.Uid, keepDeleted bool) string {
if keepDeleted {
return topic + ":" + user.String() + ":any"
@@ -3596,6 +3614,7 @@ func (messagesMapper) PersistPrepared(tenantID types.TenantID, msg *types.Messag
logs.Warn.Printf("topic[%s]: failed to mark message (seq: %d) read by sender - err: %+v", msg.Topic, msg.SeqId, subErr)
} else {
invalidateSubscriptionCache(tenantID, msg.Topic, fromUid)
DeleteCachedUserUnreadCount(tenantID, fromUid)
markedReadBySender = true
}
}