|
|
@@ -0,0 +1,110 @@
|
|
|
+# 改进URS关系缓存重建命令支持指定用户处理
|
|
|
+
|
|
|
+## 任务时间
|
|
|
+- 开始时间:2025年07月05日 03:00:04 CST
|
|
|
+- 完成时间:2025年07月05日 03:30:00 CST
|
|
|
+
|
|
|
+## 任务背景
|
|
|
+用户反馈URS推荐系统中的缓存生成存在逻辑bug,缓存不应该基于缓存生成,要从关系表中读取数据。同时需要改进UrsRebuildRelationCacheCommand命令,支持指定用户处理功能。
|
|
|
+
|
|
|
+## 问题分析
|
|
|
+1. **缓存生成逻辑错误**:原逻辑中存在基于现有缓存生成新缓存的问题,导致循环依赖
|
|
|
+2. **路径链不完整**:用户44578有多级推荐关系,但缓存只生成了部分级别
|
|
|
+3. **缺少指定用户处理功能**:命令只能全量重建,无法针对特定用户操作
|
|
|
+
|
|
|
+## 解决方案
|
|
|
+
|
|
|
+### 1. 新增指定用户处理功能
|
|
|
+在`UrsRebuildRelationCacheCommand`中添加以下参数:
|
|
|
+- `--user=` : 指定单个URS用户ID
|
|
|
+- `--users=` : 指定多个URS用户ID(逗号分隔)
|
|
|
+- `--clear` : 清除指定用户的缓存
|
|
|
+
|
|
|
+### 2. 修复缓存生成逻辑
|
|
|
+- 移除`generateIndirectRelationsFromExistingCache`方法
|
|
|
+- 修改`generateIndirectRelationsFromUrsChain`方法,完全基于URS推荐关系表生成缓存
|
|
|
+- 修复路径链构建逻辑,确保完整的路径链传递
|
|
|
+
|
|
|
+### 3. 完善命令功能
|
|
|
+- 添加用户ID验证
|
|
|
+- 改进错误处理和用户反馈
|
|
|
+- 添加进度条显示
|
|
|
+- 更新命令帮助和使用示例
|
|
|
+
|
|
|
+## 实现细节
|
|
|
+
|
|
|
+### 命令参数扩展
|
|
|
+```php
|
|
|
+protected $signature = 'urs:rebuild-relation-cache
|
|
|
+ {--batch-size=100 : 批处理大小}
|
|
|
+ {--check : 仅检查完整性,不重建}
|
|
|
+ {--fix : 修复发现的问题}
|
|
|
+ {--user= : 指定URS用户ID,仅处理该用户}
|
|
|
+ {--users= : 指定多个URS用户ID,用逗号分隔}
|
|
|
+ {--clear : 清除指定用户的缓存(需配合--user或--users使用)}';
|
|
|
+```
|
|
|
+
|
|
|
+### 逻辑修复
|
|
|
+1. **移除错误的缓存依赖逻辑**:
|
|
|
+ ```php
|
|
|
+ // 原错误逻辑(已删除)
|
|
|
+ $upperRelations = UrsUserRelationCache::where('urs_user_id', $ursReferrerId)->get();
|
|
|
+
|
|
|
+ // 修复后的逻辑
|
|
|
+ $this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $ursReferrerId, 1);
|
|
|
+ ```
|
|
|
+
|
|
|
+2. **修复路径链构建**:
|
|
|
+ ```php
|
|
|
+ // 构建完整的路径链
|
|
|
+ $newUrsPath = empty($currentUrsPath) ? (string)$upperUrsReferrerId : $currentUrsPath . ',' . $upperUrsReferrerId;
|
|
|
+ $newFarmPath = empty($currentFarmPath) ? $upperFarmPart : $currentFarmPath . ',' . $upperFarmPart;
|
|
|
+ ```
|
|
|
+
|
|
|
+## 测试验证
|
|
|
+
|
|
|
+### 测试用例:用户44578
|
|
|
+**推荐关系链**:44578 -> 44572 -> 10387 -> 10002 -> 1
|
|
|
+
|
|
|
+**修复前**:只有1级缓存
|
|
|
+```
|
|
|
+Depth 1: related_urs_id=44572, path=44572
|
|
|
+```
|
|
|
+
|
|
|
+**修复后**:完整的4级缓存
|
|
|
+```
|
|
|
+Depth 1: related_urs_id=44572, urs_path=44572, farm_path=40124
|
|
|
+Depth 2: related_urs_id=10387, urs_path=44572,10387, farm_path=40124,39172
|
|
|
+Depth 3: related_urs_id=10002, urs_path=44572,10387,10002, farm_path=40124,39172,39186
|
|
|
+Depth 4: related_urs_id=1, urs_path=44572,10387,10002,1, farm_path=40124,39172,39186,0
|
|
|
+```
|
|
|
+
|
|
|
+### 命令测试
|
|
|
+```bash
|
|
|
+# 指定单个用户
|
|
|
+php artisan urs:rebuild-relation-cache --user=44578
|
|
|
+
|
|
|
+# 指定多个用户
|
|
|
+php artisan urs:rebuild-relation-cache --users=44578,10387
|
|
|
+
|
|
|
+# 清除指定用户缓存
|
|
|
+php artisan urs:rebuild-relation-cache --user=44578 --clear
|
|
|
+
|
|
|
+# 无效用户ID处理
|
|
|
+php artisan urs:rebuild-relation-cache --user=999999
|
|
|
+# 输出:所有指定的用户ID都无效
|
|
|
+```
|
|
|
+
|
|
|
+## 代码变更
|
|
|
+- 修改文件:`app/Module/UrsPromotion/Commands/UrsRebuildRelationCacheCommand.php`
|
|
|
+- 修改文件:`app/Module/UrsPromotion/Logics/UrsRelationCacheLogic.php`
|
|
|
+- 新增方法:`handleSpecificUsers()`, `getSpecifiedUserIds()`, `validateUserIds()`, `clearSpecificUsersCache()`, `rebuildSpecificUsersCache()`
|
|
|
+- 删除方法:`generateIndirectRelationsFromExistingCache()`, `buildCombinedFarmPath()`, `buildCombinedUrsPath()`, `buildFarmUserPath()`, `buildUrsPath()`
|
|
|
+
|
|
|
+## 总结
|
|
|
+1. **成功修复**了缓存生成的逻辑bug,改为完全基于URS推荐关系表生成
|
|
|
+2. **新增**了指定用户处理功能,提高了命令的灵活性
|
|
|
+3. **修复**了路径链构建问题,确保缓存数据的完整性和正确性
|
|
|
+4. **完善**了错误处理和用户体验
|
|
|
+
|
|
|
+该改进解决了用户反馈的核心问题,提升了URS推荐系统缓存的可靠性和维护效率。
|