用户反馈URS推荐系统中的缓存生成存在逻辑bug,缓存不应该基于缓存生成,要从关系表中读取数据。同时需要改进UrsRebuildRelationCacheCommand命令,支持指定用户处理功能。
在UrsRebuildRelationCacheCommand中添加以下参数:
--user= : 指定单个URS用户ID--users= : 指定多个URS用户ID(逗号分隔)--clear : 清除指定用户的缓存generateIndirectRelationsFromExistingCache方法generateIndirectRelationsFromUrsChain方法,完全基于URS推荐关系表生成缓存protected $signature = 'urs:rebuild-relation-cache
{--batch-size=100 : 批处理大小}
{--check : 仅检查完整性,不重建}
{--fix : 修复发现的问题}
{--user= : 指定URS用户ID,仅处理该用户}
{--users= : 指定多个URS用户ID,用逗号分隔}
{--clear : 清除指定用户的缓存(需配合--user或--users使用)}';
移除错误的缓存依赖逻辑:
// 原错误逻辑(已删除)
$upperRelations = UrsUserRelationCache::where('urs_user_id', $ursReferrerId)->get();
// 修复后的逻辑
$this->generateIndirectRelationsFromUrsChain($ursUserId, $farmUserId, $ursReferrerId, 1);
修复路径链构建:
// 构建完整的路径链
$newUrsPath = empty($currentUrsPath) ? (string)$upperUrsReferrerId : $currentUrsPath . ',' . $upperUrsReferrerId;
$newFarmPath = empty($currentFarmPath) ? $upperFarmPart : $currentFarmPath . ',' . $upperFarmPart;
推荐关系链: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
# 指定单个用户
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.phpapp/Module/UrsPromotion/Logics/UrsRelationCacheLogic.phphandleSpecificUsers(), getSpecifiedUserIds(), validateUserIds(), clearSpecificUsersCache(), rebuildSpecificUsersCache()generateIndirectRelationsFromExistingCache(), buildCombinedFarmPath(), buildCombinedUrsPath(), buildFarmUserPath(), buildUrsPath()该改进解决了用户反馈的核心问题,提升了URS推荐系统缓存的可靠性和维护效率。