feat(worker): add device registration_id cleanup worker
All checks were successful
Build Backend / build (push) Successful in 2m18s
Build Backend / build-docker (push) Successful in 1m19s

Add DeviceCleanupWorker to periodically clean up stale device tokens that haven't
been used within the retention period. This prevents accumulation of invalid
registration_ids and maintains data hygiene.

- New DeviceCleanupConfig with enabled, retention_days (3), and interval_minutes (360)
- New repository methods DeleteStaleDevices and DeleteOldestActiveDevice
- Updated RegisterDevice to evict oldest active device when reaching limit
- Reduced MaxDevicesPerUser from 10 to 3 per user
- Worker integrated into app startup/shutdown lifecycle
This commit is contained in:
lafay
2026-06-18 20:34:22 +08:00
parent cb85c62093
commit 322aa9eebb
10 changed files with 303 additions and 8 deletions

View File

@@ -61,6 +61,7 @@ var ServiceSet = wire.NewSet(
ProvideQRCodeLoginService,
ProvideHotRankWorker,
ProvideFileCleanupWorker,
ProvideDeviceCleanupWorker,
ProvideMaterialService,
ProvideCallService,
ProvideLiveKitService,
@@ -312,6 +313,19 @@ func ProvideFileCleanupWorker(
return service.NewFileCleanupWorker(cfg, uploadedRepo, s3Client, rdb)
}
// ProvideDeviceCleanupWorker 提供设备 registration_id 清理 worker
func ProvideDeviceCleanupWorker(
cfg *config.Config,
deviceRepo repository.DeviceTokenRepository,
redisClient *redis.Client,
) *service.DeviceCleanupWorker {
var rdb *redisPkg.Client
if redisClient != nil {
rdb = redisClient.GetClient()
}
return service.NewDeviceCleanupWorker(cfg, deviceRepo, rdb)
}
// ProvideUserActivityService 提供用户活跃统计服务
func ProvideUserActivityService(repo repository.UserActivityRepository) service.UserActivityService {
return service.NewUserActivityService(repo)