Private
Public Access
1
0

chg: dev: add RecentBattle entity that is a Materialized View to speed up the view - and further refactor on ProfileController #8

This commit is contained in:
2026-04-20 21:08:15 +02:00
parent 6a5ba84b5e
commit 2ec37a802b
7 changed files with 341 additions and 35 deletions

View File

@@ -16,9 +16,10 @@ use App\Dto\ProfileGameDto;
use App\Dto\ProfileGameDtoFactory;
use App\Dto\ProfileStatsDto;
use App\Dto\ProfileViewDto;
use App\Entity\PlayedGame;
use App\Entity\User;
use App\Entity\RecentBattle;
use App\Repository\PlayedGameRepository;
use App\Repository\RecentBattleRepository;
use App\Repository\UserStatsRepository;
use App\Service\BattleCardGenerator;
use App\Service\WebAuthnService;
@@ -59,6 +60,7 @@ class ProfileController extends AbstractController
private readonly LoggerInterface $logger,
private readonly PlayedGameRepository $repo,
private readonly UserStatsRepository $userStatsRepo,
private readonly RecentBattleRepository $recentBattleRepo,
private readonly WebAuthnService $webAuthnService,
private readonly ProfileGameDtoFactory $profileGameDtoFactory,
private readonly ProfileChartDataFactory $profileChartDataFactory,
@@ -74,10 +76,10 @@ class ProfileController extends AbstractController
$userId = $user->id;
$stats = ProfileStatsDto::fromUserStats($this->userStatsRepo->findByUserId($userId));
$recent = $this->repo->findRecentFinishedForUser($user, 30);
$recent = $this->recentBattleRepo->findRecentForUser($userId, 30);
$gamesData = array_map(
fn(PlayedGame $game): ProfileGameDto => $this->profileGameDtoFactory->create($game, $userId),
fn(RecentBattle $battle): ProfileGameDto => $this->profileGameDtoFactory->createFromRecentBattle($battle),
$recent,
);