fix: use group message shard directory

This commit is contained in:
richjohnrambo
2026-09-27 00:40:24 +08:00
parent 6e416fcfd0
commit 021169555a
2 changed files with 22 additions and 4 deletions
+13
View File
@@ -89,6 +89,19 @@ func TestGroupMessageQuerySupportsOperationalFilters(t *testing.T) {
}
}
func TestLegacyGroupMessagesUseShardDirectory(t *testing.T) {
query := strings.ToLower(internalLegacyGroupMessagesSelect(types.TenantID(9)))
if strings.Contains(query, "im_group_message_topic_shards") {
t.Fatalf("legacy group message query must not use removed topic shard routes: %s", query)
}
if !strings.Contains(query, "im_group_message_shards") {
t.Fatalf("legacy group message query must use group message shard directory: %s", query)
}
if !strings.Contains(query, "legacy.created_at>=route.shard_start") || !strings.Contains(query, "legacy.created_at<route.shard_end") {
t.Fatalf("legacy group message query must exclude rows covered by shard windows: %s", query)
}
}
func TestLoginAuditQuerySpecsExposeUserIDAsString(t *testing.T) {
spec := internalTenantResourceSpecs["user-login-logs"]
if spec == nil {
+9 -4
View File
@@ -461,14 +461,19 @@ func internalGroupMessageSource(tenantID types.TenantID) (string, error) {
}
selects = append(selects, fmt.Sprintf(`SELECT message_id AS id,tenant_id,topic,seqid,from_user,msg_type,status,content,head,reply_seqid,mentioned_user_ids,created_at,updated_at FROM %s`, table))
}
selects = append(selects, internalLegacyGroupMessagesSelect(tenantID))
return "(" + strings.Join(selects, " UNION ALL ") + ")", nil
}
func internalLegacyGroupMessagesSelect(tenantID types.TenantID) string {
// legacy 行内联租户条件(tenantID 来自租户注册表数值 ID,非用户输入)
selects = append(selects, fmt.Sprintf(`SELECT id,tenant_id,topic COLLATE utf8mb4_0900_ai_ci AS topic,seqid,from_user,
return fmt.Sprintf(`SELECT id,tenant_id,topic COLLATE utf8mb4_0900_ai_ci AS topic,seqid,from_user,
msg_type COLLATE utf8mb4_0900_ai_ci AS msg_type,status COLLATE utf8mb4_0900_ai_ci AS status,
content,head,reply_seqid,mentioned_user_ids,created_at,updated_at
FROM im_group_messages AS legacy WHERE legacy.tenant_id=%d AND NOT EXISTS (
SELECT 1 FROM im_group_message_topic_shards AS route
WHERE route.topic=legacy.topic COLLATE utf8mb4_0900_ai_ci AND legacy.seqid BETWEEN route.min_seq AND route.max_seq)`, int64(tenantID)))
return "(" + strings.Join(selects, " UNION ALL ") + ")", nil
SELECT 1 FROM im_group_message_shards AS route
WHERE route.tenant_id=legacy.tenant_id AND route.status<>'archived'
AND legacy.created_at>=route.shard_start AND legacy.created_at<route.shard_end)`, int64(tenantID))
}
func validInternalGroupMessageTable(table string) bool {