优化用户资料卡成就摘要查询
This commit is contained in:
@@ -161,14 +161,8 @@ class UserController extends Controller
|
||||
'expires_at' => $signIdentity->expires_at?->toIso8601String(),
|
||||
] : null,
|
||||
];
|
||||
// 名片展示前先静默补算一次,避免进度已达标但解锁记录尚未落库。
|
||||
$this->achievementService->scanUser($targetUser);
|
||||
$achievementDisplay = $this->achievementService->displayForUser($targetUser);
|
||||
$data['achievements'] = [
|
||||
'unlocked_count' => $achievementDisplay['unlocked_count'],
|
||||
'total_count' => $achievementDisplay['total_count'],
|
||||
'recent' => $this->achievementService->recentUnlockedForUser($targetUser, 5)->values()->all(),
|
||||
];
|
||||
// 名片弹窗只读取已缓存的成就摘要,避免双击用户时同步扫描全量日志造成卡顿。
|
||||
$data['achievements'] = $this->achievementService->profileSummaryForUser($targetUser);
|
||||
|
||||
// 管理员网络信息仅对站长或拥有「封IP」职务权限的操作者展示。
|
||||
$canViewNetworkInfo = $operator
|
||||
|
||||
@@ -194,6 +194,23 @@ class AchievementService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取用户资料卡使用的成就摘要。
|
||||
*
|
||||
* @return array{unlocked_count: int, total_count: int, recent: array<int, array<string, mixed>>}
|
||||
*/
|
||||
public function profileSummaryForUser(User $user): array
|
||||
{
|
||||
return [
|
||||
'unlocked_count' => (int) UserAchievement::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereNotNull('achieved_at')
|
||||
->count(),
|
||||
'total_count' => count(AchievementCatalog::definitions()),
|
||||
'recent' => $this->recentUnlockedForUser($user, 5)->values()->all(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 聚合单个用户所有成就进度。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user