fix: review fixes — cache Wikidata calls, add timeout, improve escaping, hide empty popovers
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,7 @@ class GameGridGenerator
|
||||
$rowOrder = 0;
|
||||
$usedMovieRoleIds = [];
|
||||
$usedHintKeys = [];
|
||||
$cachedAwards = null;
|
||||
|
||||
foreach (str_split(strtolower($mainActor->getName())) as $char) {
|
||||
if (!preg_match('/[a-z]/', $char)) {
|
||||
@@ -57,7 +58,7 @@ class GameGridGenerator
|
||||
$row->setPosition(strpos(strtolower($actor->getName()), $char));
|
||||
$row->setRowOrder($rowOrder);
|
||||
|
||||
$hint = $this->generateHint($mainActor, $usedMovieRoleIds, $usedHintKeys);
|
||||
$hint = $this->generateHint($mainActor, $usedMovieRoleIds, $usedHintKeys, $cachedAwards);
|
||||
if ($hint !== null) {
|
||||
$row->setHintType($hint['type']);
|
||||
$row->setHintData($hint['data']);
|
||||
@@ -138,13 +139,13 @@ class GameGridGenerator
|
||||
* @param list<string> $usedHintKeys Semantic keys like "film:42" to avoid duplicate hints
|
||||
* @return array{type: string, data: string}|null
|
||||
*/
|
||||
private function generateHint(Actor $mainActor, array &$usedMovieRoleIds, array &$usedHintKeys): ?array
|
||||
private function generateHint(Actor $mainActor, array &$usedMovieRoleIds, array &$usedHintKeys, ?array &$cachedAwards): ?array
|
||||
{
|
||||
$types = ['film', 'character', 'award'];
|
||||
shuffle($types);
|
||||
|
||||
foreach ($types as $type) {
|
||||
$hint = $this->resolveHint($type, $mainActor, $usedMovieRoleIds, $usedHintKeys);
|
||||
$hint = $this->resolveHint($type, $mainActor, $usedMovieRoleIds, $usedHintKeys, $cachedAwards);
|
||||
if ($hint !== null) {
|
||||
return $hint;
|
||||
}
|
||||
@@ -158,7 +159,7 @@ class GameGridGenerator
|
||||
* @param list<string> $usedHintKeys
|
||||
* @return array{type: string, data: string}|null
|
||||
*/
|
||||
private function resolveHint(string $type, Actor $mainActor, array &$usedMovieRoleIds, array &$usedHintKeys): ?array
|
||||
private function resolveHint(string $type, Actor $mainActor, array &$usedMovieRoleIds, array &$usedHintKeys, ?array &$cachedAwards): ?array
|
||||
{
|
||||
switch ($type) {
|
||||
case 'film':
|
||||
@@ -196,12 +197,15 @@ class GameGridGenerator
|
||||
return ['type' => 'character', 'data' => $roleId];
|
||||
|
||||
case 'award':
|
||||
try {
|
||||
$awards = $this->wikidataAwardGateway->getAwards($mainActor);
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
if ($cachedAwards === null) {
|
||||
try {
|
||||
$cachedAwards = $this->wikidataAwardGateway->getAwards($mainActor);
|
||||
} catch (\Throwable) {
|
||||
$cachedAwards = [];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
foreach ($awards as $award) {
|
||||
foreach ($cachedAwards as $award) {
|
||||
$text = $award['name'] . ' (' . $award['year'] . ')';
|
||||
$key = 'award:' . $text;
|
||||
if (!in_array($key, $usedHintKeys)) {
|
||||
|
||||
Reference in New Issue
Block a user