mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Flatten the screenshot capture batch
Build the task list with a foreach over the theme map instead of a closure-returning closure that captured the same variables twice, and return failures from the coroutines instead of threading a by-reference error string that left null slots in the results. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b10a2bdcb4
commit
d99a780494
1 file changed
+14
-15
@@ -156,30 +156,29 @@ class Screenshots extends Action
|
||||
$framework = Config::getParam('frameworks', [])[$site->getAttribute('framework', '')] ?? null;
|
||||
$sleep = $framework['screenshotSleep'] ?? 3000;
|
||||
|
||||
$themes = ['screenshotLight' => 'light', 'screenshotDark' => 'dark'];
|
||||
|
||||
$screenshotError = null;
|
||||
$captures = batch(\array_map(function ($key) use ($themes, $screenshots, $routerHost, $headers, $sleep, &$screenshotError) {
|
||||
return function () use ($key, $themes, $screenshots, $routerHost, $headers, $sleep, &$screenshotError) {
|
||||
$tasks = [];
|
||||
foreach (['screenshotLight' => 'light', 'screenshotDark' => 'dark'] as $key => $theme) {
|
||||
// batch() doesn't propagate exceptions out of coroutines; return them instead.
|
||||
$tasks[] = function () use ($key, $theme, $screenshots, $routerHost, $headers, $sleep) {
|
||||
try {
|
||||
$theme = $themes[$key];
|
||||
$screenshot = $screenshots->create(
|
||||
return ['key' => $key, 'screenshot' => $screenshots->create(
|
||||
url: $routerHost . '/?appwrite-preview=1&appwrite-theme=' . $theme,
|
||||
theme: $theme,
|
||||
headers: $headers,
|
||||
sleep: $sleep,
|
||||
);
|
||||
|
||||
return ['key' => $key, 'screenshot' => $screenshot];
|
||||
)];
|
||||
} catch (\Throwable $th) {
|
||||
$screenshotError = $th->getMessage();
|
||||
return;
|
||||
return $th;
|
||||
}
|
||||
};
|
||||
}, \array_keys($themes)));
|
||||
}
|
||||
|
||||
if (!\is_null($screenshotError)) {
|
||||
throw new \Exception($screenshotError);
|
||||
$captures = [];
|
||||
foreach (batch($tasks) as $capture) {
|
||||
if ($capture instanceof \Throwable) {
|
||||
throw $capture;
|
||||
}
|
||||
$captures[] = $capture;
|
||||
}
|
||||
|
||||
Span::add('screenshot.count', \count($captures));
|
||||
|
||||
Reference in new issue
Block a user