Skip to content

Commit c4669e9

Browse files
cubercslmoesoha
andcommitted
Cache the results of getAssetFiles
Fix the disk backlog during scoreboard pictures rendering. Signed-off-by: cubercsl <[email protected]> Co-authored-by: Soha Jin <[email protected]>
1 parent 74a851b commit c4669e9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

webapp/src/Service/DOMJudgeService.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,16 +1340,24 @@ public function apiRelativeUrl(string $route, array $params = []): string
13401340
return substr($route, strlen($apiRootRoute) + $offset);
13411341
}
13421342

1343+
1344+
/** @var array<string, string[]> */
1345+
private static array $assetFiles = [];
1346+
13431347
/**
13441348
* Get asset files in the given directory with the given extension
13451349
*
13461350
* @return string[]
13471351
*/
13481352
public function getAssetFiles(string $path): array
13491353
{
1354+
if (isset(self::$assetFiles[$path])) {
1355+
return self::$assetFiles[$path];
1356+
}
1357+
13501358
$customDir = sprintf('%s/public/%s', $this->params->get('kernel.project_dir'), $path);
13511359
if (!is_dir($customDir)) {
1352-
return [];
1360+
return self::$assetFiles[$path] = [];
13531361
}
13541362

13551363
$results = [];
@@ -1361,7 +1369,7 @@ public function getAssetFiles(string $path): array
13611369
}
13621370
}
13631371

1364-
return $results;
1372+
return self::$assetFiles[$path] = $results;
13651373
}
13661374

13671375
/**

0 commit comments

Comments
 (0)