From 65e55a111901a856aa6c38eb238a4a2ffe5f25cb Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 19 Nov 2026 14:37:31 +0100 Subject: [PATCH 1/2] cmds.secrets.lib.DistroContext: Batch file listing code The compile phase of a secrets deploy makes one SSH round-trip per package to list the package files. On a host with nine packages, that is nine round-trips. Make match_files() pass the whole name list to pkg_paths() in one call: the distro backends already accept a list and issue a single file-listing command. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2 Signed-off-by: Jan Lindemann --- src/python/jw/pkg/cmds/secrets/lib/DistroContext.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py b/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py index 3006a1a2..de01258f 100644 --- a/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py +++ b/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py @@ -33,11 +33,12 @@ class DistroContext(FilesContext): self.__distro = distro async def match_files(self, pkg_names: Collection[str], pattern: str) -> list[str]: + # -- One query for the whole name list: the distro backends + # accept a list and issue a single file-listing command ret: list[str] = [] - for pkg_name in pkg_names: - for path in await self.__distro.pkg_paths(pkg_name): - if re.match(pattern, path): - ret.append(path) + for path in await self.__distro.pkg_paths(list(pkg_names)): + if re.match(pattern, path): + ret.append(path) return ret async def list_template_files(self, pkg_names: Collection[str]) -> list[str]: -- 2.56.1 From 7cec4007da1f4e56c7f8688779779c39f2f721a5 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 20 Nov 2026 05:22:27 +0100 Subject: [PATCH 2/2] cmds.secrets.lib.DistroContext: Hold ctx + store open Each run() call opens and closes the exec context, so a compile that issues one remote command at a time opened and closed the SSH connection for every command: a single deploy on dynamix opened around a hundred sessions and took several minutes. run() opens and closes through the FileContext reference counter, so holding the context (and the secret store) open for the whole compile turns the per-command open() / close() pairs into counter bumps, and the connection is established only once. This commit wraps the target listing and the per-target loop in an "async with" on both, which drops the counter to zero at end of scope and closes the contexts. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.2 Signed-off-by: Jan Lindemann --- .../jw/pkg/cmds/secrets/lib/DistroContext.py | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py b/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py index de01258f..6a5ac7cd 100644 --- a/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py +++ b/src/python/jw/pkg/cmds/secrets/lib/DistroContext.py @@ -90,20 +90,25 @@ class DistroContext(FilesContext): ret: list[str] = [] failed: list[str] = [] missing = 0 - targets = await self.list_compilation_targets(pkg_names) - for target in targets: - try: - ok = await self.compile_template_file(target, default_attrs) - except Exception as e: - if not keep_going: - raise - log(ERR, f'{target}: {e}') - failed.append(target) - continue - if ok: - ret.append(target) - else: - missing += 1 + # -- Keep the exec context and the store open across the whole + # compile, so the run() calls in the per-target operations + # bump the reference counter instead of opening and closing + # the connection for every remote command. + async with self.ctx, self.store: + targets = await self.list_compilation_targets(pkg_names) + for target in targets: + try: + ok = await self.compile_template_file(target, default_attrs) + except Exception as e: + if not keep_going: + raise + log(ERR, f'{target}: {e}') + failed.append(target) + continue + if ok: + ret.append(target) + else: + missing += 1 if missing > 0: from ....lib.util import pretty_cmd -- 2.56.1