fix: use group message shard directory
This commit is contained in:
@@ -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) {
|
func TestLoginAuditQuerySpecsExposeUserIDAsString(t *testing.T) {
|
||||||
spec := internalTenantResourceSpecs["user-login-logs"]
|
spec := internalTenantResourceSpecs["user-login-logs"]
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
|
|||||||
@@ -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, 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,非用户输入)
|
// 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,
|
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
|
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 (
|
FROM im_group_messages AS legacy WHERE legacy.tenant_id=%d AND NOT EXISTS (
|
||||||
SELECT 1 FROM im_group_message_topic_shards AS route
|
SELECT 1 FROM im_group_message_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)))
|
WHERE route.tenant_id=legacy.tenant_id AND route.status<>'archived'
|
||||||
return "(" + strings.Join(selects, " UNION ALL ") + ")", nil
|
AND legacy.created_at>=route.shard_start AND legacy.created_at<route.shard_end)`, int64(tenantID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func validInternalGroupMessageTable(table string) bool {
|
func validInternalGroupMessageTable(table string) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user