Skip to content

Cache base image metadata to speed up GetBase#521

Merged
dmitry-lyfar merged 1 commit into
mainfrom
fix/slow-get-base
Oct 24, 2025
Merged

Cache base image metadata to speed up GetBase#521
dmitry-lyfar merged 1 commit into
mainfrom
fix/slow-get-base

Conversation

@jonathan-conder
Copy link
Copy Markdown
Contributor

Description

The slow part of GetBase is downloading a big JSON file with all the images inside. LXD has a builtin mechanism to cache this download for 1 hour. We just need to give it a place to store the data.

Self-review quick check

  • Make decisions that cost a lot to reverse explicit in the PR description.
  • Avoid nested conditions.
  • Delete dead code and redundant comments.
  • Normalise symmetries by sticking to doing identical things identically.
// one way to handle errors
if err := f(); err != nil {
   ...
}

// one way to handle multiple returns
val, err := f()
if err != nil {
   ...
}
...
  • Check that coupled code elements, files, and directories are adjacent. For example, test data is stored as close as possible to a test.
  • Put variable declaration and initialisation together.
  • Divide large expressions into digestable and self-explanatory ones. Use multiple variables if required.
  • Put a blank line between two logically different chunks of code.
  • Follow the style guide for new error messages.

Docs

  • I have checked and added or updated relevant documentation.
  • I have checked and added or updated relevant release notes.
  • I have included the technical author in the review.

Or:

  • I confirm the PR has no implications for documentation.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves performance of the GetBase operation by implementing caching for base image metadata downloads. The LXD library already supports caching downloaded JSON metadata for 1 hour; this PR enables that feature by providing a cache directory path.

Key changes:

  • Introduces a new BaseDownloads cache directory for storing base image metadata
  • Passes the cache path to the LXD SimpleStreams connection
  • Fixes the image type parameter in GetImageAliasType to use the correct source field

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/dirs/dirs.go Adds BaseDownloads directory variable and ensures it's created during initialization
internal/workshop/lxd/lxd_base_manager.go Enables metadata caching by passing cache path to SimpleStreams connection and fixes image type parameter

Comment thread internal/workshop/lxd/lxd_base_manager.go
@github-actions
Copy link
Copy Markdown

TICS Quality Gate

✔️ Passed

workshop

All conditions passed

See the results in the TICS Viewer

The following files have been checked for this project
  • internal/dirs/dirs.go
  • internal/workshop/lxd/lxd_base_manager.go

Automatic-tests / code-coverage / TICS GitHub Action

@dmitry-lyfar dmitry-lyfar merged commit b47a7da into main Oct 24, 2025
12 checks passed
@dmitry-lyfar dmitry-lyfar deleted the fix/slow-get-base branch October 24, 2025 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants