Skip to content

Cache koji builds#748

Open
glehmann wants to merge 4 commits into
masterfrom
gln/koji-build-cache-qtkz
Open

Cache koji builds#748
glehmann wants to merge 4 commits into
masterfrom
gln/koji-build-cache-qtkz

Conversation

@glehmann

Copy link
Copy Markdown
Member

in order to decrease the load on koji. With what's currently in the pipe, we decrease the number of koji calls from 65 to 37 with the cache.

@glehmann

Copy link
Copy Markdown
Member Author

It would be great if it could be validated quickly—this might have an impact on koji, but only once merged 🙂

def get_koji_build(session, build_id) -> dict:
cache_key = f'koji-build-{build_id}'
if not args.re_cache and cache_key in CACHE:
return cast(dict, CACHE[cache_key])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the cast looks necessary just because CACHE itself cannot be properly type-hinted?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thinking twice about it, CACHE could be typed using a TypeDict?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think it would fit well.

I could assert isinstance(…) instead of casting if you prefer

else:
build = session.getBuild(build_id)
CACHE.set(cache_key, build, expire=RETENTION_TIME)
return build

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

instead of managing such a cache manually, wouldn't get_koji_build = functools.cache(session.getBuild) do the job? I guess other uses of CACHE could also go that same way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that's a persistent cache, using diskcache. I don't think functool has anything similar.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, right. Looks like this is a common pattern, though, and there are some libs for this, like:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there is a memoize() decorator in diskcache, but it doesn't fit well with the command line option to refresh the cache

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

or maybe I can set the expire property after creating the CACHE object. I'll check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Apparently, I can't do that. I would have loved to use CACHE.memoize(), but it really doesn't fit well with the cache customization from the CLI.

@stormi

stormi commented Oct 24, 2025

Copy link
Copy Markdown
Member

What's the status? Does this need a re-review by @ydirson, or changes prior to this?

@glehmann glehmann requested a review from ydirson October 27, 2025 15:54
in order to simply the cache usage in a next commit

Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
in order to decrease the load on koji. With what's currently in the pipe, we
decrease the number of koji calls from 65 to 37 with the cache.

Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
@glehmann glehmann force-pushed the gln/koji-build-cache-qtkz branch from 932a4ff to 8c24bc7 Compare March 12, 2026 10:05
glehmann and others added 2 commits March 12, 2026 12:18
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
@stormi stormi requested a review from a team as a code owner June 24, 2026 10:18
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.

4 participants