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:
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user