|
1 | 1 | # Package discovery and metadata functions for DependabotHelper.jl |
2 | 2 |
|
| 3 | +# Cache for GeneralMetadata.jl API responses |
| 4 | +# Key: package name, Value: Dict of version => registration date |
| 5 | +const GENERAL_METADATA_CACHE = Dict{String, Dict{String, Any}}() |
| 6 | + |
3 | 7 | """ |
4 | 8 | get_latest_version(package_name::String, package_uuid::String) |
5 | 9 |
|
@@ -493,34 +497,31 @@ end |
493 | 497 |
|
494 | 498 | Fetch the registration date for a specific version from GeneralMetadata.jl API. |
495 | 499 | Returns an ISO 8601 datetime string or nothing if not available. |
| 500 | +Uses a session-level cache to avoid redundant API calls during batch operations. |
496 | 501 | """ |
497 | 502 | function fetch_general_registry_release_date(package_name::String, version::String) |
498 | 503 | try |
499 | | - # GeneralMetadata.jl API endpoint |
500 | | - url = "https://juliaregistries.github.io/GeneralMetadata.jl/api/$package_name/versions.json" |
501 | | - |
502 | | - # Download and parse the JSON |
503 | | - temp_file = Downloads.download(url) |
504 | | - json_content = read(temp_file, String) |
505 | | - rm(temp_file; force=true) |
506 | | - |
507 | | - json_data = JSON.parse(json_content) |
| 504 | + # Fetch and cache package data if not already present |
| 505 | + cached_data = get!(GENERAL_METADATA_CACHE, package_name) do |
| 506 | + url = "https://juliaregistries.github.io/GeneralMetadata.jl/api/$package_name/versions.json" |
| 507 | + temp_file = Downloads.download(url) |
| 508 | + json_content = read(temp_file, String) |
| 509 | + rm(temp_file; force=true) |
| 510 | + JSON.parse(json_content) |
| 511 | + end |
508 | 512 |
|
509 | | - # The JSON structure is a dictionary with version strings as keys: |
510 | | - # {"0.21.0": {"registered": "2019-07-16T19:58:10"}, "1.2.0": {"registered": "2025-10-17T01:08:11"}, ...} |
511 | | - if json_data isa AbstractDict && haskey(json_data, version) |
512 | | - version_info = json_data[version] |
| 513 | + # Look up the version from cache |
| 514 | + if cached_data isa AbstractDict && haskey(cached_data, version) |
| 515 | + version_info = cached_data[version] |
513 | 516 | if version_info isa AbstractDict && haskey(version_info, "registered") |
514 | 517 | return string(version_info["registered"]) |
515 | 518 | end |
516 | 519 | end |
517 | 520 |
|
518 | | - # Version not found or no timestamp available |
519 | 521 | return nothing |
520 | 522 |
|
521 | 523 | catch e |
522 | 524 | @error "fetch_general_registry_release_date: Failed to fetch from GeneralMetadata.jl" package_name=package_name version=version exception=(e, catch_backtrace()) |
523 | | - # Don't fail completely, just return nothing |
524 | 525 | return nothing |
525 | 526 | end |
526 | 527 | end# Args wrapper for get_version_release_date function with UUID requirement |
|
0 commit comments