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:
@@ -29,6 +29,7 @@ final class GitHubProviderTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<int, array{contributionDays: array<int, array{date: string, contributionCount: int}>}> $weeks */
|
||||
private function stubGraphqlResponse(array $weeks): ResponseInterface
|
||||
{
|
||||
$response = $this->createStub(ResponseInterface::class);
|
||||
@@ -131,4 +132,27 @@ final class GitHubProviderTest extends TestCase
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_narrows_the_graphql_query_window_when_since_and_until_are_given(): void
|
||||
{
|
||||
$since = new \DateTimeImmutable('2024-01-01');
|
||||
$until = new \DateTimeImmutable('2024-01-31');
|
||||
$capturedQuery = null;
|
||||
|
||||
$client = $this->createMock(HttpClientInterface::class);
|
||||
$client->method('request')->willReturnCallback(
|
||||
function (string $method, string $url, array $options) use (&$capturedQuery): ResponseInterface {
|
||||
$capturedQuery = $options['json']['query'];
|
||||
|
||||
return $this->stubGraphqlResponse([]);
|
||||
}
|
||||
);
|
||||
|
||||
$provider = $this->makeProvider(client: $client);
|
||||
$provider->startFetch($since, $until);
|
||||
|
||||
$this->assertStringContainsString('2024-01-01T00:00:00Z', $capturedQuery);
|
||||
$this->assertStringContainsString('2024-01-31T23:59:59Z', $capturedQuery);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user