feat: enhance schedule publish account handling and caching mechanisms
Frontend CI / Frontend (push) Successful in 3m1s
Backend CI / Backend (push) Failing after 6m51s

This commit is contained in:
2026-06-21 09:11:37 +08:00
parent c1b06dab18
commit 37d75597f9
6 changed files with 125 additions and 54 deletions
+46 -11
View File
@@ -70,36 +70,71 @@ func loadPublishAccountPlatformsByIDs(
tenantID int64,
accountIDs []string,
) ([]string, error) {
_, platformIDs, err := loadExistingPublishAccountIDsAndPlatformsByIDs(ctx, db, tenantID, 0, accountIDs)
return platformIDs, err
}
func LoadExistingSchedulePublishAccountIDsAndPlatformsByIDs(
ctx context.Context,
db scheduleAutoPublishPlatformQuerier,
tenantID int64,
workspaceID int64,
accountIDs []string,
) ([]string, []string, error) {
return loadExistingPublishAccountIDsAndPlatformsByIDs(ctx, db, tenantID, workspaceID, accountIDs)
}
func loadExistingPublishAccountIDsAndPlatformsByIDs(
ctx context.Context,
db scheduleAutoPublishPlatformQuerier,
tenantID int64,
workspaceID int64,
accountIDs []string,
) ([]string, []string, error) {
accountIDs = normalizeSchedulePublishAccountIDs(accountIDs)
if db == nil || tenantID <= 0 || len(accountIDs) == 0 {
return []string{}, nil
return []string{}, []string{}, nil
}
rows, err := db.Query(ctx, `
SELECT DISTINCT platform_id
SELECT DISTINCT desktop_id::text, platform_id
FROM platform_accounts
WHERE tenant_id = $1
AND desktop_id::text = ANY($2::text[])
AND ($3::bigint <= 0 OR workspace_id = $3)
AND deleted_at IS NULL
ORDER BY platform_id
`, tenantID, accountIDs)
`, tenantID, accountIDs, workspaceID)
if err != nil {
return nil, err
return nil, nil, err
}
defer rows.Close()
platformIDs := make([]string, 0, len(accountIDs))
platformsByAccount := make(map[string][]string, len(accountIDs))
existingByAccount := make(map[string]struct{}, len(accountIDs))
for rows.Next() {
var accountID string
var platformID string
if err := rows.Scan(&platformID); err != nil {
return nil, err
if err := rows.Scan(&accountID, &platformID); err != nil {
return nil, nil, err
}
platformIDs = append(platformIDs, platformID)
platformsByAccount[accountID] = append(platformsByAccount[accountID], platformID)
existingByAccount[accountID] = struct{}{}
}
if err := rows.Err(); err != nil {
return nil, err
return nil, nil, err
}
return emptyStringSliceIfNil(normalizePlatformIDs(platformIDs)), nil
existingAccountIDs := make([]string, 0, len(accountIDs))
platformIDs := make([]string, 0, len(accountIDs))
for _, accountID := range accountIDs {
if _, ok := existingByAccount[accountID]; !ok {
continue
}
existingAccountIDs = append(existingAccountIDs, accountID)
platformIDs = append(platformIDs, platformsByAccount[accountID]...)
}
return emptyStringSliceIfNil(existingAccountIDs), emptyStringSliceIfNil(normalizePlatformIDs(platformIDs)), nil
}
func emptyStringSliceIfNil(values []string) []string {