feat(aggregator): fetch all providers concurrently
aggregate() now fires every configured provider's startFetch() in one pass before resolving any of them, so wall-clock cost is roughly max(providers) instead of sum(providers). Partial-failure isolation and per-date summation behavior are unchanged.
This commit is contained in:
@@ -19,7 +19,7 @@ final class ContributionAggregator
|
|||||||
/** @return array<string, int> */
|
/** @return array<string, int> */
|
||||||
public function aggregate(): array
|
public function aggregate(): array
|
||||||
{
|
{
|
||||||
$contributions = [];
|
$pending = [];
|
||||||
|
|
||||||
/** @var ProviderInterface $provider */
|
/** @var ProviderInterface $provider */
|
||||||
foreach ($this->providers as $provider) {
|
foreach ($this->providers as $provider) {
|
||||||
@@ -28,7 +28,17 @@ final class ContributionAggregator
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($provider->fetch() as $date => $count) {
|
$pending[] = [$provider, $provider->startFetch()];
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->logger->warning(sprintf('%s fetch failed: %s', $provider::class, $e->getMessage()), ['exception' => $e]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$contributions = [];
|
||||||
|
|
||||||
|
foreach ($pending as [$provider, $handle]) {
|
||||||
|
try {
|
||||||
|
foreach ($provider->resolveFetch($handle) as $date => $count) {
|
||||||
$contributions[$date] = ($contributions[$date] ?? 0) + $count;
|
$contributions[$date] = ($contributions[$date] ?? 0) + $count;
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user