fix(mysql): route tenant data to physical shard tables

This commit is contained in:
richjohnrambo
2026-09-22 16:11:10 +08:00
parent 76b462e334
commit b8c93e8d6a
2 changed files with 14 additions and 10 deletions
+10 -6
View File
@@ -9,19 +9,23 @@ import (
t "github.com/tinode/chat/server/store/types"
)
func tenantFriendshipsTable(t.TenantID) string {
return "im_friendships"
func tenantTablePrefix(tenantID t.TenantID) string {
return fmt.Sprintf("im_%03d_", tenantID)
}
func tenantMessagesTable(t.TenantID) string {
return "im_messages"
func tenantFriendshipsTable(tenantID t.TenantID) string {
return tenantTablePrefix(tenantID) + "friendships"
}
func tenantGroupMessagesTable(_ t.TenantID, month string) (string, bool) {
func tenantMessagesTable(tenantID t.TenantID) string {
return tenantTablePrefix(tenantID) + "messages"
}
func tenantGroupMessagesTable(tenantID t.TenantID, month string) (string, bool) {
if !validShardMonth(month) {
return "", false
}
return fmt.Sprintf("im_group_messages_%s", month), true
return fmt.Sprintf("%sgroup_messages_%s", tenantTablePrefix(tenantID), month), true
}
func validShardMonth(month string) bool {