@@ -229,10 +229,15 @@ def fn():
229229_uid_cache : dict [str , str ] = {}
230230
231231
232- def find_by_uid (base_url : str , auth : str , collection : str , uid : str ) -> str | None :
232+ def _uid_cache_key (base_url : str , collection : str , uid : str ) -> str :
233+ return f"{ base_url .rstrip ('/' )} :{ collection } :{ uid } "
234+
235+
236+ def find_by_uid (base_url : str , auth : str , collection : str , uid : str ,
237+ * , no_cache : bool = False ) -> str | None :
233238 """Find a resource by UID in a collection. Returns server ID or None."""
234- cache_key = f" { collection } : { uid } "
235- if cache_key in _uid_cache :
239+ cache_key = _uid_cache_key ( base_url , collection , uid )
240+ if not no_cache and cache_key in _uid_cache :
236241 return _uid_cache [cache_key ]
237242
238243 result = api_get (base_url , f"{ collection } ?uid={ uid } &limit=1000" , auth )
@@ -244,8 +249,9 @@ def find_by_uid(base_url: str, auth: str, collection: str, uid: str) -> str | No
244249 if props .get ("uid" ) == uid :
245250 item_id = item .get ("id" ) or props .get ("id" )
246251 if item_id :
247- _uid_cache [cache_key ] = str (item_id )
248- return str (item_id )
252+ item_id = str (item_id )
253+ _uid_cache [cache_key ] = item_id
254+ return item_id
249255 return None
250256
251257
@@ -516,7 +522,7 @@ def ensure_procedure(base_url: str, auth: str, uid: str, stub_body: dict,
516522 stats .setdefault ("created" , 0 )
517523 stats ["created" ] += 1
518524 if new_id :
519- _uid_cache [f "procedures: { uid } " ] = new_id
525+ _uid_cache [_uid_cache_key ( base_url , "procedures" , uid ) ] = new_id
520526 return new_id
521527
522528
@@ -574,7 +580,7 @@ def ensure_system(base_url: str, auth: str, uid: str, stub_body: dict,
574580 stats .setdefault ("created" , 0 )
575581 stats ["created" ] += 1
576582 if new_id :
577- _uid_cache [f "systems: { uid } " ] = new_id
583+ _uid_cache [_uid_cache_key ( base_url , "systems" , uid ) ] = new_id
578584 return new_id
579585
580586
@@ -690,7 +696,7 @@ def ensure_deployment(base_url: str, auth: str, uid: str, stub_body: dict,
690696 stats .setdefault ("created" , 0 )
691697 stats ["created" ] += 1
692698 if new_id :
693- _uid_cache [f "deployments: { uid } " ] = new_id
699+ _uid_cache [_uid_cache_key ( base_url , "deployments" , uid ) ] = new_id
694700 return new_id
695701
696702
@@ -713,8 +719,7 @@ def clean_resource(base_url: str, auth: str, collection: str, uid: str,
713719 stats ["deleted" ] += 1
714720
715721 # Invalidate cache
716- cache_key = f"{ collection } :{ uid } "
717- _uid_cache .pop (cache_key , None )
722+ _uid_cache .pop (_uid_cache_key (base_url , collection , uid ), None )
718723
719724
720725# ═══════════════════════════════════════════════════════════════════════════
0 commit comments