6.6 KiB
6.6 KiB
TODO: persist contribution history in SQLite + audit cleanup
Backend-only work. Follow Red → Green → Refactor per CLAUDE.md for every
step that adds behavior (store, retention, provider $since handling).
Order matters — later steps assume earlier ones are done.
1. Audit cleanup
-
Remove
eightpoints/guzzle-bundle+idci/graphql-client-bundle. They exist only to build one near-static GitHub GraphQL query string (GitHubProvider.php:59-74); the bundle's own HTTP transport is already bypassed (comment atGitHubProvider.php:76-77).- Replace
$graphqlClient->buildQuery(...)->getGraphQLQuery()with a plainsprintf/heredoc query string. Delete the two packages fromcomposer.json,config/bundles.php, and deleteconfig/packages/eight_points_guzzle.yaml+config/packages/idci_graphql_client.yaml. Runcomposer updateand commit the regeneratedcomposer.lock.
- Replace
-
Dedupe
baseUrlnormalization.GitLabProvider.php(lines 41, 53) andGiteaProvider.php(lines 42, 54) each callrtrim($this->baseUrl..., '/')twice — once inping(), once infetch(). Compute it once as aprivate readonly string $baseUrlin the constructor instead.
2. Fix stale config/services.yaml (found during exploration, blocks step 1 & 4)
services.yamlstill binds$username/$token/$baseUrlto the pre-refactor FQCNs (App\Service\GitHubProvideretc.) and_instanceof: App\Service\ProviderInterface, left over from theService/→Provider/+Renderer/namespace reorg. Update all of these toApp\Service\Provider\.... Currently these bindings silently no-op, and scalar constructor args can't autowire without them — any edit to these constructors (steps 1, 4) needs this fixed first, or the container fails to compile.
3. ContributionStore (SQLite via native PDO)
- New
src/Service/ContributionStore.php. PDO SQLite, DB file at%kernel.project_dir%/var/data/contributions.db(configurable constructor arg), table created lazily:CREATE TABLE IF NOT EXISTS contributions ( provider TEXT NOT NULL, date TEXT NOT NULL, count INTEGER NOT NULL CHECK (count >= 0), PRIMARY KEY (provider, date) ) WITHOUT ROWID, STRICT; latestDate(string $provider): ?string—SELECT MAX(date) WHERE provider = ?.merge(string $provider, array $dateCounts): void— upsert viaINSERT ... ON CONFLICT(provider, date) DO UPDATE SET count = excluded.count.all(string $provider, ?int $sinceDays = null): array—date => count;nullreturns full history (no arbitrary cutoff), a value filters to the last N days.prune(): void—DELETE FROM contributions WHERE date < ?using the configured retention window; no-ops if retention is unset/0.- Constructor takes
?int $retentionDaysbound from new env varCONTRIBUTIONS_RETENTION_DAYS(empty/default = keep forever). - Tests:
tests/Unit/Service/ContributionStoreTest.php— store & retrieve, upsert overwrites existing date,sinceDaysfiltering,prune()no-ops when retention unset,prune()deletes rows older than the window when set.
4. Wire $since through providers
ProviderInterface::fetch()→fetch(?\DateTimeImmutable $since = null): array.GitHubProvider::fetch()— use$since ?? new \DateTimeImmutable('-365 days')for the GraphQLfromparam.GitLabProvider::fetch()— same, feeds theafterquery param (this is what actually shrinks the pagination loop).GiteaProvider::fetch()— same, feeds the$cutofftimestamp filter.- Update
GitHubProviderTest.php(dropGraphQLApiClientRegistryInterfacestub setup entirely per step 1),GitLabProviderTest.php,GiteaProviderTest.php— add a case asserting a passed$sincenarrows the request window.
5. Wire ContributionStore into ContributionAggregator
- Inject
ContributionStoreintoContributionAggregator. - Per configured provider:
$since = $store->latestDate($name)→ if set,(new \DateTimeImmutable($latest))->modify('-3 days')(3-day overlap for late corrections), elsenull(first run). $fresh = $provider->fetch($since),$store->merge($name, $fresh), then read back$store->all($name, sinceDays: 371)for the render window (53 weeks × 7 days) and merge into the returned array.- Call
$store->prune()once peraggregate()call, after all providers have merged. - Keep the existing try/catch-and-log-per-provider behavior — a provider failure leaves its DB history stale, doesn't break the render.
- Update
ContributionAggregatorTest.phpwith store-interaction and prune-call cases.
6. Docker / env
docker-compose.yml— add adatanamed volume mounted at/app/var/data(same pattern ascache/logs), and pass throughCONTRIBUTIONS_RETENTION_DAYS: "${CONTRIBUTIONS_RETENTION_DAYS:-}".Dockerfile— addvar/datato themkdir -pin thefinalstage alongsidevar/cache/prod/pools var/log, owned byapp..env— documentCONTRIBUTIONS_RETENTION_DAYS(empty by default), same style as the existingALLOWED_HOSTScomment.
7. PHPStan
composer require --dev phpstan/phpstan(plain PHPStan — no Symfony extension needed for this app's size).- Add
phpstan.neon:paths: [src, tests],level: 8. - Add composer script
"phpstan": "phpstan analyse". - Fix whatever level-8 flags on first run.
8. CLAUDE.md update
- Architecture section: add the
ContributionStore(SQLite) tier between providers and the renderer; note the two-tier cache (1h SVG cache → SQLite raw-data store → provider APIs). - Environment variables table: add
CONTRIBUTIONS_RETENTION_DAYS. - Development section: add
composer phpstannext to the existingvendor/bin/phpunitcommands. - Remove any remaining mentions of the two deleted bundles.
Verification
vendor/bin/phpunit --testdoxgreen after every step.composer phpstanclean at level 8.composer installsucceeds with no dangling references to the removed bundles.docker compose up -d --build; clear the FS cache (docker compose exec graph rm -rf var/cache/*); hit/graph.svg?theme=darktwice; checkdocker compose logs -f graphshows a narrowersincewindow on the second fetch.- Set
CONTRIBUTIONS_RETENTION_DAYS=30; confirm rows older than 30 days are gone after the next refresh (sqlite3 var/data/contributions.db "SELECT date FROM contributions ORDER BY date LIMIT 1"). curl localhost:8080/healthstill reports all configured providers healthy.