Skip to content

Commit 16b8400

Browse files
jopemachineclaude
andcommitted
refactor(BA-5837): align cache-aware admin_repo with Updater/Purger pattern
The Valkey cache wrapper added in this PR re-introduced the `(key, spec)` and `(key)` signatures on `db_source.update` / `db_source.purge`. Switch the cache-aware admin_repository over to the Updater/Purger pattern from BA-5827 while keeping the merged- view cache-invalidation hooks intact. Also rename the residual `extra_config` / `extraConfig` references in the GQL types and schema dump to `config` for consistency with the column rename. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 86db40c commit 16b8400

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

src/ai/backend/manager/repositories/app_config_fragment/admin_repository.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,39 @@ async def update(
116116
key: AppConfigFragmentKey,
117117
config: Mapping[str, Any],
118118
) -> AppConfigFragmentData:
119-
"""Update a fragment by natural key. Raises
120-
``AppConfigFragmentNotFound`` when missing."""
121-
spec = AppConfigFragmentUpdaterSpec(extra_config=extra_config)
122-
result = await self._db_source.update(key, spec)
119+
"""Update a fragment by natural key. Resolves the natural key
120+
to the row's UUID, builds an ``Updater``, and delegates to the
121+
DB source. Raises :class:`AppConfigFragmentNotFound` when the
122+
row is missing (or vanishes between resolve and write)."""
123+
pk_value = await self._db_source.resolve_pk_by_key(key)
124+
if pk_value is None:
125+
raise _missing(key)
126+
updater: Updater[AppConfigFragmentRow] = Updater(
127+
spec=AppConfigFragmentUpdaterSpec(config=config),
128+
pk_value=pk_value,
129+
)
130+
result = await self._db_source.update(updater)
131+
if result is None:
132+
raise _missing(key)
123133
await self._invalidate(key)
124134
return result
125135

126136
@app_config_fragment_admin_repository_resilience.apply()
127137
async def purge(self, key: AppConfigFragmentKey) -> bool:
128-
result = await self._db_source.purge(key)
129-
if result:
138+
"""Delete a fragment by natural key. Resolves the natural key,
139+
builds a ``Purger``, delegates to the DB source, and (on a
140+
real removal) invalidates the merged-view cache."""
141+
pk_value = await self._db_source.resolve_pk_by_key(key)
142+
if pk_value is None:
143+
return False
144+
purger: Purger[AppConfigFragmentRow] = Purger(
145+
row_class=AppConfigFragmentRow,
146+
pk_value=pk_value,
147+
)
148+
removed = await self._db_source.purge(purger)
149+
if removed:
130150
await self._invalidate(key)
131-
return result
151+
return removed
132152

133153
async def _invalidate(self, key: AppConfigFragmentKey) -> None:
134154
if self._cache_source is None:

0 commit comments

Comments
 (0)