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
+40
View File
@@ -11,6 +11,7 @@
namespace App\Dto;
use App\Entity\PlayedGame;
use App\Entity\RecentBattle;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
/**
@@ -91,4 +92,43 @@ final readonly class ProfileGameDtoFactory
return 'draw';
}
/**
* Build a ProfileGameDto directly from the recent_battles materialized view row.
* Avatar paths are still resolved via LiipImagine (they are stored as storage paths).
*/
public function createFromRecentBattle(RecentBattle $battle): ProfileGameDto
{
$myPts = $battle->isRed ? $battle->redPoints : $battle->bluePoints;
$oppPts = $battle->isRed ? $battle->bluePoints : $battle->redPoints;
return new ProfileGameDto(
id: $battle->gameId,
uuid: $battle->uuid,
redName: $battle->redName,
blueName: $battle->blueName,
redAvatar: $battle->redAvatarPath
? $this->cacheManager->generateUrl($battle->redAvatarPath, 'avatar_thumb')
: null,
blueAvatar: $battle->blueAvatarPath
? $this->cacheManager->generateUrl($battle->blueAvatarPath, 'avatar_thumb')
: null,
redPoints: $battle->redPoints,
bluePoints: $battle->bluePoints,
redExplodedBomb: $battle->redExplodedBomb,
blueExplodedBomb: $battle->blueExplodedBomb,
resign: $battle->resign,
created: $battle->created?->format('Y-m-d H:i'),
date: $battle->updated?->format('Y-m-d H:i'),
isRed: $battle->isRed,
result: $battle->result,
myPoints: $myPts,
oppPoints: $oppPts,
redBonusPoints: $battle->redBonusPoints,
blueBonusPoints: $battle->blueBonusPoints,
redBonusStats: $battle->redBonusStats,
blueBonusStats: $battle->blueBonusStats,
);
}
}