feat(store): fetch contributions incrementally and persist history in SQLite
Bound each provider's startFetch()/resolveFetch() to an optional since/until window, wire a SQLite-backed ContributionStore into ContributionAggregator (fetch only the trailing window past the last stored date, merge into the store, prune by CONTRIBUTIONS_RETENTION_DAYS), and add a graph:contributions:refetch command to force a full or ranged re-fetch in <=365-day chunks. This is the root fix for the full 365-day-refetch timeout that used to hit on every cache miss.
This commit is contained in:
@@ -31,6 +31,7 @@ final class GitLabProviderTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<int, array<string, int|string>> $data raw JSON body, e.g. events or the user lookup */
|
||||
private function stubResponse(array $data): ResponseInterface
|
||||
{
|
||||
$response = $this->createStub(ResponseInterface::class);
|
||||
@@ -128,4 +129,27 @@ final class GitLabProviderTest extends TestCase
|
||||
$this->assertSame(100, $result['2024-06-10']);
|
||||
$this->assertSame(1, $result['2024-06-11']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_sends_after_and_before_query_params_when_since_and_until_are_given(): void
|
||||
{
|
||||
$capturedQuery = null;
|
||||
|
||||
$client = $this->createMock(HttpClientInterface::class);
|
||||
$client->method('request')->willReturnCallback(
|
||||
function (string $method, string $url, array $options = []) use (&$capturedQuery): ResponseInterface {
|
||||
if (str_contains($url, '/events')) {
|
||||
$capturedQuery = $options['query'];
|
||||
}
|
||||
|
||||
return $this->stubResponse(str_contains($url, '/events') ? [] : [['id' => 42]]);
|
||||
}
|
||||
);
|
||||
|
||||
$provider = $this->makeProvider(client: $client);
|
||||
$provider->startFetch(new \DateTimeImmutable('2024-01-01'), new \DateTimeImmutable('2024-01-31'));
|
||||
|
||||
$this->assertSame('2024-01-01', $capturedQuery['after']);
|
||||
$this->assertSame('2024-01-31', $capturedQuery['before']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user