Browse Source

改进URS关系缓存重建命令和逻辑

1. 新增指定用户处理功能:
   - 支持--user参数处理单个用户
   - 支持--users参数处理多个用户(逗号分隔)
   - 支持--clear参数清除指定用户缓存
   - 添加用户ID验证和错误处理

2. 修复缓存生成逻辑bug:
   - 移除基于缓存生成缓存的错误逻辑
   - 改为完全基于URS推荐关系表生成缓存
   - 修复路径链构建逻辑,确保完整的路径链
   - 删除不再使用的方法

3. 完善命令功能:
   - 更新命令帮助和使用示例
   - 添加进度条显示
   - 改进错误处理和用户反馈
dongasai 6 months ago
parent
commit
79d5be90f9

+ 253 - 14
app/Module/UrsPromotion/Commands/UrsRebuildRelationCacheCommand.php

@@ -7,23 +7,34 @@ use Illuminate\Console\Command;
 
 /**
  * URS用户关系缓存重建命令
- * 
+ *
  * 用于批量重建URS用户关系缓存,提升查询性能
+ *
+ * 使用示例:
+ * php artisan urs:rebuild-relation-cache                    # 重建所有用户缓存
+ * php artisan urs:rebuild-relation-cache --check            # 检查缓存完整性
+ * php artisan urs:rebuild-relation-cache --fix              # 修复发现的问题
+ * php artisan urs:rebuild-relation-cache --user=123         # 重建指定用户缓存
+ * php artisan urs:rebuild-relation-cache --users=123,456    # 重建多个用户缓存
+ * php artisan urs:rebuild-relation-cache --user=123 --clear # 清除指定用户缓存
  */
 class UrsRebuildRelationCacheCommand extends Command
 {
     /**
      * 命令签名
      */
-    protected $signature = 'urs:rebuild-relation-cache 
+    protected $signature = 'urs:rebuild-relation-cache
                             {--batch-size=100 : 批处理大小}
                             {--check : 仅检查完整性,不重建}
-                            {--fix : 修复发现的问题}';
+                            {--fix : 修复发现的问题}
+                            {--user= : 指定URS用户ID,仅处理该用户}
+                            {--users= : 指定多个URS用户ID,用逗号分隔}
+                            {--clear : 清除指定用户的缓存(需配合--user或--users使用)}';
 
     /**
      * 命令描述
      */
-    protected $description = 'URS用户关系缓存重建命令';
+    protected $description = 'URS用户关系缓存重建命令,支持全量重建、指定用户处理、完整性检查和问题修复';
 
     /**
      * 执行命令
@@ -31,7 +42,12 @@ class UrsRebuildRelationCacheCommand extends Command
     public function handle()
     {
         $logic = new UrsRelationCacheLogic();
-        
+
+        // 处理指定用户的缓存操作
+        if ($this->option('user') || $this->option('users')) {
+            return $this->handleSpecificUsers($logic);
+        }
+
         // 仅检查完整性
         if ($this->option('check')) {
             $this->info('开始检查URS关系缓存完整性...');
@@ -63,19 +79,47 @@ class UrsRebuildRelationCacheCommand extends Command
         // 修复问题
         if ($this->option('fix')) {
             $this->info('开始修复URS关系缓存问题...');
-            $result = $logic->fixRelationCacheIssues();
-            
+
+            // 先检查需要修复的数量
+            $integrity = $logic->checkRelationCacheIntegrity();
+            $totalToFix = $integrity['missing_users'] + $integrity['orphaned_caches'];
+
+            if ($totalToFix == 0) {
+                $this->info('没有发现需要修复的问题');
+                return 0;
+            }
+
+            $progressBar = $this->output->createProgressBar($totalToFix);
+            $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% - %message%');
+            $progressBar->setMessage('准备修复...');
+            $progressBar->start();
+
+            $currentProgress = 0;
+
+            // 定义进度回调函数
+            $progressCallback = function($type, $ursUserId, $processed, $total, $fixed) use ($progressBar, &$currentProgress) {
+                $currentProgress++;
+                $typeText = $type === 'missing' ? '修复缺失缓存' : '清理孤立缓存';
+                $progressBar->setMessage("{$typeText} - URS用户ID: {$ursUserId} (已修复: {$fixed})");
+                $progressBar->setProgress($currentProgress);
+            };
+
+            $result = $logic->fixRelationCacheIssues($progressCallback);
+
+            $progressBar->finish();
+            $this->newLine();
+
             if (isset($result['error'])) {
                 $this->error('修复失败: ' . $result['error']);
                 return 1;
             }
-            
+
             $this->info('修复结果:');
             $this->table(['项目', '修复数量'], [
                 ['缺失用户缓存', $result['fixed']['missing_users']],
                 ['孤立缓存清理', $result['fixed']['orphaned_caches']]
             ]);
-            
+
             $this->info('问题修复完成');
             return 0;
         }
@@ -89,12 +133,23 @@ class UrsRebuildRelationCacheCommand extends Command
         }
         
         $this->info("开始重建URS关系缓存,批处理大小: {$batchSize}");
-        
-        $progressBar = $this->output->createProgressBar();
+
+        // 先获取总用户数用于进度条初始化
+        $totalUsers = \App\Module\UrsPromotion\Models\UrsUserReferral::where('status', \App\Module\UrsPromotion\Models\UrsUserReferral::STATUS_VALID)->count();
+
+        $progressBar = $this->output->createProgressBar($totalUsers);
+        $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% - 当前用户ID: %message%');
+        $progressBar->setMessage('准备开始...');
         $progressBar->start();
-        
-        $result = $logic->rebuildAllRelationCache($batchSize);
-        
+
+        // 定义进度回调函数
+        $progressCallback = function($ursUserId, $processedCount, $totalUsers, $successCount, $failCount) use ($progressBar) {
+            $progressBar->setMessage("URS用户ID: {$ursUserId} (成功: {$successCount}, 失败: {$failCount})");
+            $progressBar->setProgress($processedCount);
+        };
+
+        $result = $logic->rebuildAllRelationCache($batchSize, $progressCallback);
+
         $progressBar->finish();
         $this->newLine();
         
@@ -118,4 +173,188 @@ class UrsRebuildRelationCacheCommand extends Command
         $this->info('所有URS用户关系缓存重建完成');
         return 0;
     }
+
+    /**
+     * 处理指定用户的缓存操作
+     *
+     * @param UrsRelationCacheLogic $logic
+     * @return int
+     */
+    private function handleSpecificUsers(UrsRelationCacheLogic $logic): int
+    {
+        // 获取用户ID列表
+        $userIds = $this->getSpecifiedUserIds();
+
+        if (empty($userIds)) {
+            $this->error('未指定有效的用户ID');
+            return 1;
+        }
+
+        $this->info('指定处理的URS用户ID: ' . implode(', ', $userIds));
+
+        // 验证用户ID是否存在
+        $validUserIds = $this->validateUserIds($userIds);
+        if (empty($validUserIds)) {
+            $this->error('所有指定的用户ID都无效');
+            return 1;
+        }
+
+        if (count($validUserIds) < count($userIds)) {
+            $invalidIds = array_diff($userIds, $validUserIds);
+            $this->warn('以下用户ID无效,将被跳过: ' . implode(', ', $invalidIds));
+        }
+
+        // 清除缓存操作
+        if ($this->option('clear')) {
+            return $this->clearSpecificUsersCache($logic, $validUserIds);
+        }
+
+        // 重建指定用户的缓存
+        return $this->rebuildSpecificUsersCache($logic, $validUserIds);
+    }
+
+    /**
+     * 获取指定的用户ID列表
+     *
+     * @return array
+     */
+    private function getSpecifiedUserIds(): array
+    {
+        $userIds = [];
+
+        // 处理单个用户ID
+        if ($this->option('user')) {
+            $userId = (int) $this->option('user');
+            if ($userId > 0) {
+                $userIds[] = $userId;
+            }
+        }
+
+        // 处理多个用户ID
+        if ($this->option('users')) {
+            $usersString = $this->option('users');
+            $userIdStrings = explode(',', $usersString);
+
+            foreach ($userIdStrings as $userIdString) {
+                $userId = (int) trim($userIdString);
+                if ($userId > 0 && !in_array($userId, $userIds)) {
+                    $userIds[] = $userId;
+                }
+            }
+        }
+
+        return $userIds;
+    }
+
+    /**
+     * 验证用户ID是否存在于URS推荐关系中
+     *
+     * @param array $userIds
+     * @return array
+     */
+    private function validateUserIds(array $userIds): array
+    {
+        return \App\Module\UrsPromotion\Models\UrsUserReferral::whereIn('urs_user_id', $userIds)
+            ->where('status', \App\Module\UrsPromotion\Models\UrsUserReferral::STATUS_VALID)
+            ->pluck('urs_user_id')
+            ->toArray();
+    }
+
+    /**
+     * 清除指定用户的缓存
+     *
+     * @param UrsRelationCacheLogic $logic
+     * @param array $userIds
+     * @return int
+     */
+    private function clearSpecificUsersCache(UrsRelationCacheLogic $logic, array $userIds): int
+    {
+        $this->info('开始清除指定用户的关系缓存...');
+
+        $progressBar = $this->output->createProgressBar(count($userIds));
+        $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% - 当前用户ID: %message%');
+        $progressBar->start();
+
+        $successCount = 0;
+        $failCount = 0;
+
+        foreach ($userIds as $userId) {
+            $progressBar->setMessage("URS用户ID: {$userId}");
+
+            if ($logic->clearUserRelationCache($userId)) {
+                $successCount++;
+            } else {
+                $failCount++;
+            }
+
+            $progressBar->advance();
+        }
+
+        $progressBar->finish();
+        $this->newLine();
+
+        $this->info('缓存清除完成:');
+        $this->table(['项目', '数量'], [
+            ['处理用户数', count($userIds)],
+            ['成功数', $successCount],
+            ['失败数', $failCount]
+        ]);
+
+        if ($failCount > 0) {
+            $this->warn('部分用户缓存清除失败,请检查日志');
+            return 1;
+        }
+
+        $this->info('指定用户关系缓存清除完成');
+        return 0;
+    }
+
+    /**
+     * 重建指定用户的缓存
+     *
+     * @param UrsRelationCacheLogic $logic
+     * @param array $userIds
+     * @return int
+     */
+    private function rebuildSpecificUsersCache(UrsRelationCacheLogic $logic, array $userIds): int
+    {
+        $this->info('开始重建指定用户的关系缓存...');
+
+        $progressBar = $this->output->createProgressBar(count($userIds));
+        $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% - 当前用户ID: %message%');
+        $progressBar->start();
+
+        $successCount = 0;
+        $failCount = 0;
+
+        foreach ($userIds as $userId) {
+            $progressBar->setMessage("URS用户ID: {$userId}");
+
+            if ($logic->generateUserRelationCache($userId)) {
+                $successCount++;
+            } else {
+                $failCount++;
+            }
+
+            $progressBar->advance();
+        }
+
+        $progressBar->finish();
+        $this->newLine();
+
+        $this->info('缓存重建完成:');
+        $this->table(['项目', '数量'], [
+            ['处理用户数', count($userIds)],
+            ['成功数', $successCount],
+            ['失败数', $failCount]
+        ]);
+
+        if ($failCount > 0) {
+            $this->warn('部分用户缓存生成失败,请检查日志');
+            return 1;
+        }
+
+        $this->info('指定用户关系缓存重建完成');
+        return 0;
+    }
 }

+ 51 - 115
app/Module/UrsPromotion/Logics/UrsRelationCacheLogic.php

@@ -79,7 +79,7 @@ class UrsRelationCacheLogic
                 }
 
                 // 尝试获取推荐人的上级关系(基于URS关系)
-                $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $ursReferrerId, 1);
+                $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $ursReferrerId, 1, (string)$ursReferrerId, '0');
 
                 Log::info("URS用户 {$ursUserId} 占位缓存记录创建完成");
                 return true;
@@ -97,31 +97,8 @@ class UrsRelationCacheLogic
             $directRelation->depth = 1;
             $directRelation->save();
 
-            // 获取推荐人的所有上级(限制在20代以内)
-            $upperRelations = UrsUserRelationCache::where('urs_user_id', $ursReferrerId)
-                ->where('depth', '<', UrsPromotionRelationLevel::getMaxLevel())
-                ->get();
-
-            // 创建间接关系缓存(最多20代)
-            foreach ($upperRelations as $upperRelation) {
-                $newDepth = $upperRelation->depth + 1;
-
-                // 限制最大深度为20代
-                if ($newDepth > UrsPromotionRelationLevel::getMaxLevel()) {
-                    continue;
-                }
-
-                $indirectRelation = new UrsUserRelationCache();
-                $indirectRelation->user_id = $farmUserId;
-                $indirectRelation->related_user_id = $upperRelation->related_user_id;
-                $indirectRelation->urs_user_id = $ursUserId;
-                $indirectRelation->urs_related_user_id = $upperRelation->urs_related_user_id;
-                $indirectRelation->level = UrsPromotionRelationLevel::getLevelByDepth($newDepth);
-                $indirectRelation->path = $farmReferrerId . ',' . $upperRelation->path;
-                $indirectRelation->urs_path = $ursReferrerId . ',' . $upperRelation->urs_path;
-                $indirectRelation->depth = $newDepth;
-                $indirectRelation->save();
-            }
+            // 基于URS推荐关系链直接生成所有间接关系(不依赖缓存)
+            $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $ursReferrerId, 1, (string)$ursReferrerId, (string)$farmReferrerId);
 
             // 清除Redis缓存
             Redis::del("urs_promotion:user:{$ursUserId}:all_referrers");
@@ -147,9 +124,11 @@ class UrsRelationCacheLogic
      * @param int $farmUserId 当前用户的农场用户ID
      * @param int $currentUrsReferrerId 当前层级的URS推荐人ID
      * @param int $currentDepth 当前深度
+     * @param string $currentUrsPath 当前URS路径链
+     * @param string $currentFarmPath 当前农场路径链
      * @return void
      */
-    private function generateIndirectRelationsFromUrsChain(int $ursUserId, int $farmUserId, int $currentUrsReferrerId, int $currentDepth): void
+    private function generateIndirectRelationsFromUrsChain(int $ursUserId, int $farmUserId, int $currentUrsReferrerId, int $currentDepth, string $currentUrsPath = '', string $currentFarmPath = ''): void
     {
         // 限制最大深度为20代
         if ($currentDepth >= UrsPromotionRelationLevel::getMaxLevel()) {
@@ -170,6 +149,13 @@ class UrsRelationCacheLogic
         $upperFarmReferrerId = UrsUserMappingService::getFarmUserId($upperUrsReferrerId);
         $newDepth = $currentDepth + 1;
 
+        // 构建新的路径链
+        $newUrsPath = empty($currentUrsPath) ? (string)$upperUrsReferrerId : $currentUrsPath . ',' . $upperUrsReferrerId;
+        $currentFarmReferrerId = UrsUserMappingService::getFarmUserId($currentUrsReferrerId);
+        $currentFarmPart = $currentFarmReferrerId > 0 ? (string)$currentFarmReferrerId : '0';
+        $upperFarmPart = $upperFarmReferrerId > 0 ? (string)$upperFarmReferrerId : '0';
+        $newFarmPath = empty($currentFarmPath) ? $upperFarmPart : $currentFarmPath . ',' . $upperFarmPart;
+
         if ($upperFarmReferrerId > 0) {
             // 检查是否已存在该深度的关系缓存
             $existingCache = UrsUserRelationCache::where('urs_user_id', $ursUserId)
@@ -185,8 +171,8 @@ class UrsRelationCacheLogic
                 $indirectRelation->urs_user_id = $ursUserId;
                 $indirectRelation->urs_related_user_id = $upperUrsReferrerId;
                 $indirectRelation->level = UrsPromotionRelationLevel::getLevelByDepth($newDepth);
-                $indirectRelation->path = $this->buildFarmUserPath($currentUrsReferrerId, $upperFarmReferrerId);
-                $indirectRelation->urs_path = $this->buildUrsPath($currentUrsReferrerId, $upperUrsReferrerId);
+                $indirectRelation->path = $newFarmPath;
+                $indirectRelation->urs_path = $newUrsPath;
                 $indirectRelation->depth = $newDepth;
                 $indirectRelation->save();
             }
@@ -197,8 +183,8 @@ class UrsRelationCacheLogic
                 'depth' => $newDepth
             ]);
 
-            // 继续向上查找,基于已有的关系缓存
-            $this->generateIndirectRelationsFromExistingCache($ursUserId, $farmUserId, $upperUrsReferrerId, $newDepth);
+            // 继续向上递归查找,基于URS推荐关系链
+            $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $upperUrsReferrerId, $newDepth, $newUrsPath, $newFarmPath);
         } else {
             // 检查是否已存在该深度的占位缓存
             $existingCache = UrsUserRelationCache::where('urs_user_id', $ursUserId)
@@ -214,101 +200,22 @@ class UrsRelationCacheLogic
                 $indirectRelation->urs_user_id = $ursUserId;
                 $indirectRelation->urs_related_user_id = $upperUrsReferrerId;
                 $indirectRelation->level = UrsPromotionRelationLevel::getLevelByDepth($newDepth);
-                $indirectRelation->path = $this->buildFarmUserPath($currentUrsReferrerId, 0);
-                $indirectRelation->urs_path = $this->buildUrsPath($currentUrsReferrerId, $upperUrsReferrerId);
+                $indirectRelation->path = $newFarmPath;
+                $indirectRelation->urs_path = $newUrsPath;
                 $indirectRelation->depth = $newDepth;
                 $indirectRelation->save();
             }
 
             // 继续向上递归查找
-            $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $upperUrsReferrerId, $newDepth);
+            $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $upperUrsReferrerId, $newDepth, $newUrsPath, $newFarmPath);
         }
     }
 
-    /**
-     * 基于已有关系缓存生成间接关系
-     *
-     * @param int $ursUserId 当前用户的URS用户ID
-     * @param int $farmUserId 当前用户的农场用户ID
-     * @param int $baseUrsReferrerId 基准URS推荐人ID
-     * @param int $baseDepth 基准深度
-     * @return void
-     */
-    private function generateIndirectRelationsFromExistingCache(int $ursUserId, int $farmUserId, int $baseUrsReferrerId, int $baseDepth): void
-    {
-        // 获取基准推荐人的所有上级关系缓存
-        $upperRelations = UrsUserRelationCache::where('urs_user_id', $baseUrsReferrerId)
-            ->where('depth', '<', UrsPromotionRelationLevel::getMaxLevel() - $baseDepth)
-            ->get();
 
-        foreach ($upperRelations as $upperRelation) {
-            $newDepth = $baseDepth + $upperRelation->depth;
 
-            // 限制最大深度为20代
-            if ($newDepth > UrsPromotionRelationLevel::getMaxLevel()) {
-                continue;
-            }
 
-            // 检查是否已存在该深度的关系缓存
-            $existingCache = UrsUserRelationCache::where('urs_user_id', $ursUserId)
-                ->where('urs_related_user_id', $upperRelation->urs_related_user_id)
-                ->where('depth', $newDepth)
-                ->first();
 
-            if (!$existingCache) {
-                $indirectRelation = new UrsUserRelationCache();
-                $indirectRelation->user_id = $farmUserId;
-                $indirectRelation->related_user_id = $upperRelation->related_user_id;
-                $indirectRelation->urs_user_id = $ursUserId;
-                $indirectRelation->urs_related_user_id = $upperRelation->urs_related_user_id;
-                $indirectRelation->level = UrsPromotionRelationLevel::getLevelByDepth($newDepth);
-                $indirectRelation->path = $this->buildCombinedFarmPath($baseUrsReferrerId, $upperRelation->path);
-                $indirectRelation->urs_path = $this->buildCombinedUrsPath($baseUrsReferrerId, $upperRelation->urs_path);
-                $indirectRelation->depth = $newDepth;
-                $indirectRelation->save();
-            }
-        }
-    }
 
-    /**
-     * 构建农场用户路径
-     */
-    private function buildFarmUserPath(int $currentUrsReferrerId, int $upperFarmReferrerId): string
-    {
-        $currentFarmReferrerId = UrsUserMappingService::getFarmUserId($currentUrsReferrerId);
-        $currentPart = $currentFarmReferrerId > 0 ? (string)$currentFarmReferrerId : '0';
-
-        if ($upperFarmReferrerId > 0) {
-            return $currentPart . ',' . $upperFarmReferrerId;
-        }
-        return $currentPart;
-    }
-
-    /**
-     * 构建URS用户路径
-     */
-    private function buildUrsPath(int $currentUrsReferrerId, int $upperUrsReferrerId): string
-    {
-        return $currentUrsReferrerId . ',' . $upperUrsReferrerId;
-    }
-
-    /**
-     * 构建组合农场用户路径
-     */
-    private function buildCombinedFarmPath(int $baseUrsReferrerId, string $upperPath): string
-    {
-        $baseFarmReferrerId = UrsUserMappingService::getFarmUserId($baseUrsReferrerId);
-        $basePart = $baseFarmReferrerId > 0 ? (string)$baseFarmReferrerId : '0';
-        return $basePart . ',' . $upperPath;
-    }
-
-    /**
-     * 构建组合URS用户路径
-     */
-    private function buildCombinedUrsPath(int $baseUrsReferrerId, string $upperUrsPath): string
-    {
-        return $baseUrsReferrerId . ',' . $upperUrsPath;
-    }
 
     /**
      * 清除用户的关系缓存
@@ -345,9 +252,10 @@ class UrsRelationCacheLogic
      * 重建所有用户的关系缓存
      *
      * @param int $batchSize 批处理大小
+     * @param callable|null $progressCallback 进度回调函数
      * @return array 包含成功和失败的数量
      */
-    public function rebuildAllRelationCache(int $batchSize = 100): array
+    public function rebuildAllRelationCache(int $batchSize = 100, ?callable $progressCallback = null): array
     {
         try {
             // 清空关系缓存表
@@ -370,12 +278,21 @@ class UrsRelationCacheLogic
 
             $successCount = 0;
             $failCount = 0;
+            $totalUsers = count($ursUserIds);
+            $processedCount = 0;
 
             // 分批处理
             $chunks = array_chunk($ursUserIds, $batchSize);
 
             foreach ($chunks as $chunk) {
                 foreach ($chunk as $ursUserId) {
+                    $processedCount++;
+
+                    // 调用进度回调函数
+                    if ($progressCallback) {
+                        $progressCallback($ursUserId, $processedCount, $totalUsers, $successCount, $failCount);
+                    }
+
                     if ($this->generateUserRelationCache($ursUserId)) {
                         $successCount++;
                     } else {
@@ -453,9 +370,10 @@ class UrsRelationCacheLogic
     /**
      * 修复关系缓存问题
      *
+     * @param callable|null $progressCallback 进度回调函数
      * @return array 包含修复结果
      */
-    public function fixRelationCacheIssues(): array
+    public function fixRelationCacheIssues(?callable $progressCallback = null): array
     {
         try {
             // 检查完整性
@@ -473,8 +391,17 @@ class UrsRelationCacheLogic
                     ->pluck('urs_user_id')
                     ->toArray();
                 $missingUsers = array_diff($allUsers, $usersWithCache);
+                $totalMissing = count($missingUsers);
+                $processedMissing = 0;
 
                 foreach ($missingUsers as $ursUserId) {
+                    $processedMissing++;
+
+                    // 调用进度回调函数
+                    if ($progressCallback) {
+                        $progressCallback('missing', $ursUserId, $processedMissing, $totalMissing, $fixed['missing_users']);
+                    }
+
                     if ($this->generateUserRelationCache($ursUserId)) {
                         $fixed['missing_users']++;
                     }
@@ -489,8 +416,17 @@ class UrsRelationCacheLogic
                     LEFT JOIN kku_urs_promotion_user_referrals r ON c.urs_user_id = r.urs_user_id AND r.status = 1
                     WHERE r.urs_user_id IS NULL
                 ");
+                $totalOrphaned = count($orphanedCaches);
+                $processedOrphaned = 0;
 
                 foreach ($orphanedCaches as $cache) {
+                    $processedOrphaned++;
+
+                    // 调用进度回调函数
+                    if ($progressCallback) {
+                        $progressCallback('orphaned', $cache->urs_user_id, $processedOrphaned, $totalOrphaned, $fixed['orphaned_caches']);
+                    }
+
                     if ($this->clearUserRelationCache($cache->urs_user_id)) {
                         $fixed['orphaned_caches']++;
                     }