diff --git a/backend/cmd/server/VERSION b/backend/cmd/server/VERSION index 0219e6bd2a..806863b267 100644 --- a/backend/cmd/server/VERSION +++ b/backend/cmd/server/VERSION @@ -1 +1 @@ -0.1.114.12 +0.1.114.13 diff --git a/backend/cmd/server/wire_gen.go b/backend/cmd/server/wire_gen.go index c17eec4791..3556185dcb 100644 --- a/backend/cmd/server/wire_gen.go +++ b/backend/cmd/server/wire_gen.go @@ -104,8 +104,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { proxyExitInfoProber := repository.NewProxyExitInfoProber(configConfig) proxyLatencyCache := repository.NewProxyLatencyCache(redisClient) privacyClientFactory := providePrivacyClientFactory() - scheduledTestPlanRepository := repository.NewScheduledTestPlanRepository(db) - adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService, userSubscriptionRepository, privacyClientFactory, scheduledTestPlanRepository) + adminService := service.NewAdminService(userRepository, groupRepository, accountRepository, proxyRepository, apiKeyRepository, redeemCodeRepository, userGroupRateRepository, billingCacheService, proxyExitInfoProber, proxyLatencyCache, apiKeyAuthCacheInvalidator, client, settingService, subscriptionService, userSubscriptionRepository, privacyClientFactory) concurrencyCache := repository.ProvideConcurrencyCache(redisClient, configConfig) concurrencyService := service.ProvideConcurrencyService(concurrencyCache, accountRepository, configConfig) adminUserHandler := admin.NewUserHandler(adminService, concurrencyService) @@ -207,6 +206,7 @@ func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) { errorPassthroughHandler := admin.NewErrorPassthroughHandler(errorPassthroughService) tlsFingerprintProfileHandler := admin.NewTLSFingerprintProfileHandler(tlsFingerprintProfileService) adminAPIKeyHandler := admin.NewAdminAPIKeyHandler(adminService) + scheduledTestPlanRepository := repository.NewScheduledTestPlanRepository(db) scheduledTestResultRepository := repository.NewScheduledTestResultRepository(db) scheduledTestService := service.ProvideScheduledTestService(scheduledTestPlanRepository, scheduledTestResultRepository) scheduledTestHandler := admin.NewScheduledTestHandler(scheduledTestService) diff --git a/backend/internal/repository/account_repo.go b/backend/internal/repository/account_repo.go index b4cb4dcaf7..fb9099bd8e 100644 --- a/backend/internal/repository/account_repo.go +++ b/backend/internal/repository/account_repo.go @@ -463,6 +463,9 @@ func (r *accountRepository) Delete(ctx context.Context, id int64) error { if _, err := txClient.AccountGroup.Delete().Where(dbaccountgroup.AccountIDEQ(id)).Exec(ctx); err != nil { return err } + if _, err := txClient.ExecContext(ctx, "DELETE FROM scheduled_test_plans WHERE account_id = $1", id); err != nil { + return err + } if _, err := txClient.Account.Delete().Where(dbaccount.IDEQ(id)).Exec(ctx); err != nil { return err } diff --git a/backend/internal/repository/scheduled_test_repo.go b/backend/internal/repository/scheduled_test_repo.go index 1afadad20e..c03d1df90f 100644 --- a/backend/internal/repository/scheduled_test_repo.go +++ b/backend/internal/repository/scheduled_test_repo.go @@ -77,11 +77,6 @@ func (r *scheduledTestPlanRepository) Delete(ctx context.Context, id int64) erro return err } -func (r *scheduledTestPlanRepository) DeleteByAccountID(ctx context.Context, accountID int64) error { - _, err := r.db.ExecContext(ctx, `DELETE FROM scheduled_test_plans WHERE account_id = $1`, accountID) - return err -} - func (r *scheduledTestPlanRepository) UpdateAfterRun(ctx context.Context, id int64, lastRunAt time.Time, nextRunAt time.Time) error { _, err := r.db.ExecContext(ctx, ` UPDATE scheduled_test_plans SET last_run_at = $2, next_run_at = $3, updated_at = NOW() WHERE id = $1 diff --git a/backend/internal/server/api_contract_test.go b/backend/internal/server/api_contract_test.go index 41c62c467a..a27ee647fb 100644 --- a/backend/internal/server/api_contract_test.go +++ b/backend/internal/server/api_contract_test.go @@ -731,7 +731,7 @@ func newContractDeps(t *testing.T) *contractDeps { settingRepo := newStubSettingRepo() settingService := service.NewSettingService(settingRepo, cfg) - adminService := service.NewAdminService(userRepo, groupRepo, &accountRepo, proxyRepo, apiKeyRepo, redeemRepo, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) + adminService := service.NewAdminService(userRepo, groupRepo, &accountRepo, proxyRepo, apiKeyRepo, redeemRepo, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) authHandler := handler.NewAuthHandler(cfg, nil, userService, settingService, nil, redeemService, nil) apiKeyHandler := handler.NewAPIKeyHandler(apiKeyService) usageHandler := handler.NewUsageHandler(usageService, apiKeyService) diff --git a/backend/internal/service/admin_service.go b/backend/internal/service/admin_service.go index 3c286b44e1..701f3659ee 100644 --- a/backend/internal/service/admin_service.go +++ b/backend/internal/service/admin_service.go @@ -423,23 +423,22 @@ const ( // adminServiceImpl implements AdminService type adminServiceImpl struct { - userRepo UserRepository - groupRepo GroupRepository - accountRepo AccountRepository - proxyRepo ProxyRepository - apiKeyRepo APIKeyRepository - redeemCodeRepo RedeemCodeRepository - userGroupRateRepo UserGroupRateRepository - billingCacheService *BillingCacheService - proxyProber ProxyExitInfoProber - proxyLatencyCache ProxyLatencyCache - authCacheInvalidator APIKeyAuthCacheInvalidator - entClient *dbent.Client // 用于开启数据库事务 - settingService *SettingService - defaultSubAssigner DefaultSubscriptionAssigner - userSubRepo UserSubscriptionRepository - privacyClientFactory PrivacyClientFactory - scheduledTestPlanRepo ScheduledTestPlanRepository + userRepo UserRepository + groupRepo GroupRepository + accountRepo AccountRepository + proxyRepo ProxyRepository + apiKeyRepo APIKeyRepository + redeemCodeRepo RedeemCodeRepository + userGroupRateRepo UserGroupRateRepository + billingCacheService *BillingCacheService + proxyProber ProxyExitInfoProber + proxyLatencyCache ProxyLatencyCache + authCacheInvalidator APIKeyAuthCacheInvalidator + entClient *dbent.Client // 用于开启数据库事务 + settingService *SettingService + defaultSubAssigner DefaultSubscriptionAssigner + userSubRepo UserSubscriptionRepository + privacyClientFactory PrivacyClientFactory } type userGroupRateBatchReader interface { @@ -464,26 +463,24 @@ func NewAdminService( defaultSubAssigner DefaultSubscriptionAssigner, userSubRepo UserSubscriptionRepository, privacyClientFactory PrivacyClientFactory, - scheduledTestPlanRepo ScheduledTestPlanRepository, ) AdminService { return &adminServiceImpl{ - userRepo: userRepo, - groupRepo: groupRepo, - accountRepo: accountRepo, - proxyRepo: proxyRepo, - apiKeyRepo: apiKeyRepo, - redeemCodeRepo: redeemCodeRepo, - userGroupRateRepo: userGroupRateRepo, - billingCacheService: billingCacheService, - proxyProber: proxyProber, - proxyLatencyCache: proxyLatencyCache, - authCacheInvalidator: authCacheInvalidator, - entClient: entClient, - settingService: settingService, - defaultSubAssigner: defaultSubAssigner, - userSubRepo: userSubRepo, - privacyClientFactory: privacyClientFactory, - scheduledTestPlanRepo: scheduledTestPlanRepo, + userRepo: userRepo, + groupRepo: groupRepo, + accountRepo: accountRepo, + proxyRepo: proxyRepo, + apiKeyRepo: apiKeyRepo, + redeemCodeRepo: redeemCodeRepo, + userGroupRateRepo: userGroupRateRepo, + billingCacheService: billingCacheService, + proxyProber: proxyProber, + proxyLatencyCache: proxyLatencyCache, + authCacheInvalidator: authCacheInvalidator, + entClient: entClient, + settingService: settingService, + defaultSubAssigner: defaultSubAssigner, + userSubRepo: userSubRepo, + privacyClientFactory: privacyClientFactory, } } @@ -1863,13 +1860,6 @@ func (s *adminServiceImpl) BulkUpdateAccounts(ctx context.Context, input *BulkUp } func (s *adminServiceImpl) DeleteAccount(ctx context.Context, id int64) error { - if err := s.scheduledTestPlanRepo.DeleteByAccountID(ctx, id); err != nil { - slog.Error("failed to delete scheduled test plans for account", - "account_id", id, - "error", err, - ) - return fmt.Errorf("delete scheduled test plans: %w", err) - } if err := s.accountRepo.Delete(ctx, id); err != nil { return err } diff --git a/backend/internal/service/scheduled_test_port.go b/backend/internal/service/scheduled_test_port.go index 22c9cdb8db..1c0fdf218f 100644 --- a/backend/internal/service/scheduled_test_port.go +++ b/backend/internal/service/scheduled_test_port.go @@ -41,7 +41,6 @@ type ScheduledTestPlanRepository interface { ListDue(ctx context.Context, now time.Time) ([]*ScheduledTestPlan, error) Update(ctx context.Context, plan *ScheduledTestPlan) (*ScheduledTestPlan, error) Delete(ctx context.Context, id int64) error - DeleteByAccountID(ctx context.Context, accountID int64) error UpdateAfterRun(ctx context.Context, id int64, lastRunAt time.Time, nextRunAt time.Time) error }