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:
@@ -30,6 +30,7 @@ final class GiteaProviderTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** @param array<int, array{timestamp: int, contributions: int}> $data */
|
||||
private function stubResponse(array $data): ResponseInterface
|
||||
{
|
||||
$response = $this->createStub(ResponseInterface::class);
|
||||
@@ -111,4 +112,44 @@ final class GiteaProviderTest extends TestCase
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_filters_out_entries_before_since(): void
|
||||
{
|
||||
$since = new \DateTimeImmutable('2024-01-10');
|
||||
$before = $since->modify('-1 day')->getTimestamp();
|
||||
$after = $since->modify('+1 day')->getTimestamp();
|
||||
|
||||
$client = $this->createStub(HttpClientInterface::class);
|
||||
$client->method('request')->willReturn($this->stubResponse([
|
||||
['timestamp' => $before, 'contributions' => 3],
|
||||
['timestamp' => $after, 'contributions' => 2],
|
||||
]));
|
||||
|
||||
$provider = $this->makeProvider(client: $client);
|
||||
$result = $provider->resolveFetch($provider->startFetch($since));
|
||||
|
||||
$this->assertArrayNotHasKey(date('Y-m-d', $before), $result);
|
||||
$this->assertSame(2, $result[date('Y-m-d', $after)]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_filters_out_entries_after_until(): void
|
||||
{
|
||||
$until = new \DateTimeImmutable('-10 days');
|
||||
$before = $until->modify('-1 day')->getTimestamp();
|
||||
$after = $until->modify('+1 day')->getTimestamp();
|
||||
|
||||
$client = $this->createStub(HttpClientInterface::class);
|
||||
$client->method('request')->willReturn($this->stubResponse([
|
||||
['timestamp' => $before, 'contributions' => 3],
|
||||
['timestamp' => $after, 'contributions' => 2],
|
||||
]));
|
||||
|
||||
$provider = $this->makeProvider(client: $client);
|
||||
$result = $provider->resolveFetch($provider->startFetch(null, $until));
|
||||
|
||||
$this->assertSame(3, $result[date('Y-m-d', $before)]);
|
||||
$this->assertArrayNotHasKey(date('Y-m-d', $after), $result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user