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