Skip to content

Commit 9fd1e52

Browse files
cache release date lookups
1 parent 2ea28bc commit 9fd1e52

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

julia/helpers/DependabotHelper.jl/src/package_discovery.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Package discovery and metadata functions for DependabotHelper.jl
22

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+
37
"""
48
get_latest_version(package_name::String, package_uuid::String)
59
@@ -493,34 +497,31 @@ end
493497
494498
Fetch the registration date for a specific version from GeneralMetadata.jl API.
495499
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.
496501
"""
497502
function fetch_general_registry_release_date(package_name::String, version::String)
498503
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
508512

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]
513516
if version_info isa AbstractDict && haskey(version_info, "registered")
514517
return string(version_info["registered"])
515518
end
516519
end
517520

518-
# Version not found or no timestamp available
519521
return nothing
520522

521523
catch e
522524
@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
524525
return nothing
525526
end
526527
end# Args wrapper for get_version_release_date function with UUID requirement

julia/helpers/DependabotHelper.jl/src/precompile.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
run_check_result("""{"function": "find_package_source_url", "args": {"package_name": "JSON", "package_uuid": "682c06a0-de6a-54ab-a142-c8b1cf79cde6"}}""")
4646
run_check_result("""{"function": "extract_package_metadata_from_url", "args": {"package_name": "JSON", "source_url": "https://github.com/JuliaIO/JSON.jl"}}""")
4747

48+
# Release date functions (General registry)
49+
run_check_result("""{"function": "get_version_release_date", "args": {"package_name": "JSON", "version": "0.21.0", "package_uuid": "682c06a0-de6a-54ab-a142-c8b1cf79cde6"}}""")
50+
run_check_result("""{"function": "get_available_versions", "args": {"package_name": "JSON", "package_uuid": "682c06a0-de6a-54ab-a142-c8b1cf79cde6"}}""")
51+
52+
# Batch operations
53+
run_check_result("""{"function": "batch_get_package_info", "args": {"packages": [{"name": "JSON", "uuid": "682c06a0-de6a-54ab-a142-c8b1cf79cde6"}]}}""")
54+
run_check_result("""{"function": "batch_get_available_versions", "args": {"packages": [{"name": "JSON", "uuid": "682c06a0-de6a-54ab-a142-c8b1cf79cde6"}]}}""")
55+
run_check_result("""{"function": "batch_get_version_release_dates", "args": {"packages_versions": [{"name": "JSON", "uuid": "682c06a0-de6a-54ab-a142-c8b1cf79cde6", "versions": ["0.21.0"]}]}}""")
56+
4857
# Compatibility functions (use nonexistent paths to avoid actual updates)
4958
run("""{"function": "check_update_compatibility", "args": {"project_path": "/tmp/nonexistent", "package_name": "JSON", "target_version": "0.21.4"}}""")
5059
run("""{"function": "resolve_dependencies_with_constraints", "args": {"project_path": "/tmp/nonexistent", "target_updates": {"JSON": "0.21.4"}}}""")
@@ -60,5 +69,8 @@
6069

6170
# Test missing args field (expected to return error)
6271
run("""{"function": "get_latest_version"}""")
72+
73+
# Clear the GeneralMetadata cache after precompilation workload
74+
empty!(GENERAL_METADATA_CACHE)
6375
end
6476
end

0 commit comments

Comments
 (0)