refactor(gitea): make GiteaProvider fetch non-blocking
startFetch() fires the heatmap GET and returns the response without reading it; resolveFetch() does the .toArray()/parse/log work.
This commit is contained in:
@@ -6,6 +6,7 @@ namespace App\Service\Provider;
|
|||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches contribution data from the Gitea heatmap endpoint.
|
* Fetches contribution data from the Gitea heatmap endpoint.
|
||||||
@@ -46,20 +47,24 @@ final class GiteaProvider implements ProviderInterface
|
|||||||
])->getContent();
|
])->getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function startFetch(): ResponseInterface
|
||||||
* @return array<string, int> date (Y-m-d) => contribution count
|
|
||||||
*/
|
|
||||||
public function fetch(): array
|
|
||||||
{
|
{
|
||||||
$baseUrl = rtrim($this->baseUrl, '/');
|
$baseUrl = rtrim($this->baseUrl, '/');
|
||||||
|
|
||||||
$this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]);
|
$this->logger->debug('GiteaProvider: fetching contributions', ['user' => $this->username, 'url' => $baseUrl]);
|
||||||
|
|
||||||
$response = $this->client->request('GET', "$baseUrl/api/v1/users/{$this->username}/heatmap", [
|
return $this->client->request('GET', "$baseUrl/api/v1/users/{$this->username}/heatmap", [
|
||||||
'headers' => ['Authorization' => "token {$this->token}"],
|
'headers' => ['Authorization' => "token {$this->token}"],
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$data = $response->toArray();
|
/**
|
||||||
|
* @return array<string, int> date (Y-m-d) => contribution count
|
||||||
|
*/
|
||||||
|
public function resolveFetch(mixed $handle): array
|
||||||
|
{
|
||||||
|
/** @var ResponseInterface $handle */
|
||||||
|
$data = $handle->toArray();
|
||||||
$cutoff = (new \DateTimeImmutable('-365 days'))->getTimestamp();
|
$cutoff = (new \DateTimeImmutable('-365 days'))->getTimestamp();
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user