aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-registry/src/packagist.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-24 00:23:30 +0900
committernsfisis <nsfisis@gmail.com>2026-02-24 00:23:30 +0900
commitaf0df92e1ecc82823a510646b7545278caeac4b8 (patch)
tree4b735eed50dd369895600c2f7cfd0039d274b2af /crates/mozart-registry/src/packagist.rs
parent2622fa3089d1df249276083d157e43b080a59100 (diff)
downloadphp-mozart-af0df92e1ecc82823a510646b7545278caeac4b8.tar.gz
php-mozart-af0df92e1ecc82823a510646b7545278caeac4b8.tar.zst
php-mozart-af0df92e1ecc82823a510646b7545278caeac4b8.zip
feat(cache): enable repo cache for all Packagist API calls
Remove the Option wrapper from repo_cache in ResolveRequest, LockFileGenerationRequest, and fetch_package_versions. All commands now initialize a Cache via build_cache_config(cli.no_cache), ensuring Packagist metadata is cached to disk (respecting --no-cache flag). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-registry/src/packagist.rs')
-rw-r--r--crates/mozart-registry/src/packagist.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/mozart-registry/src/packagist.rs b/crates/mozart-registry/src/packagist.rs
index 8a5f205..64ff11a 100644
--- a/crates/mozart-registry/src/packagist.rs
+++ b/crates/mozart-registry/src/packagist.rs
@@ -212,21 +212,20 @@ pub fn parse_p2_response(json: &str, package_name: &str) -> anyhow::Result<Vec<P
/// Fetch package version metadata from the Packagist p2 API.
///
-/// If `repo_cache` is provided, the JSON response is cached on disk under the
-/// key `"provider-{vendor}~{package}.json"`. Subsequent calls for the same
-/// package are served from cache without a network request.
+/// The JSON response is cached on disk under the key
+/// `"provider-{vendor}~{package}.json"`. Subsequent calls for the same
+/// package are served from cache without a network request (unless the
+/// cache is disabled).
#[tracing::instrument(skip(repo_cache))]
pub async fn fetch_package_versions(
package_name: &str,
- repo_cache: Option<&Cache>,
+ repo_cache: &Cache,
) -> anyhow::Result<Vec<PackagistVersion>> {
// Build cache key: replace `/` with `~` per cache key convention
let cache_key = format!("provider-{}.json", package_name.replace('/', "~"));
// Check cache first
- if let Some(cache) = repo_cache
- && let Some(cached) = cache.read(&cache_key)
- {
+ if let Some(cached) = repo_cache.read(&cache_key) {
tracing::debug!("cache hit");
return parse_p2_response(&cached, package_name);
}
@@ -250,9 +249,7 @@ pub async fn fetch_package_versions(
let body = response.text().await?;
// Write to cache
- if let Some(cache) = repo_cache {
- let _ = cache.write(&cache_key, &body);
- }
+ let _ = repo_cache.write(&cache_key, &body);
parse_p2_response(&body, package_name)
}