@@ -40,7 +40,7 @@ impl LocalVersions {
4040 }
4141
4242 #[ inline]
43- pub fn get ( & self , ty : & str ) -> parking_lot:: MutexGuard < ' _ , VersionMap > {
43+ fn get_map_guard ( & self , ty : & str ) -> parking_lot:: MutexGuard < ' _ , VersionMap > {
4444 let g = self
4545 . versions
4646 . iter ( )
@@ -53,6 +53,28 @@ impl LocalVersions {
5353 panic ! ( "unable to retrieve `{ty}` versions, available versions are {versions:?}" ) ;
5454 }
5555 }
56+
57+ #[ inline]
58+ pub fn update_versions ( & self , type_url : & str , removed_resources : & Vec < String > , updated_resources : Vec < ( String , String ) > ) {
59+ let mut guard = self . get_map_guard ( type_url) ;
60+
61+ // Remove any resources the upstream server has removed/doesn't have,
62+ // we do this before applying any new/updated resources in case a
63+ // resource is in both lists, though really that would be a bug in
64+ // the upstream server
65+ for removed in removed_resources {
66+ guard. remove ( removed) ;
67+ }
68+
69+ for ( k, v) in updated_resources {
70+ guard. insert ( k, v) ;
71+ }
72+ }
73+
74+ #[ inline]
75+ pub fn get_versions ( & self , type_url : & str ) -> VersionMap {
76+ self . get_map_guard ( type_url) . clone ( )
77+ }
5678}
5779
5880pub struct ClientState {
@@ -268,19 +290,7 @@ pub fn handle_delta_discovery_responses<C: Configuration>(
268290 let res = config. apply_delta( & type_url, response. resources, & response. removed_resources, remote_addr) ;
269291
270292 if res. is_ok( ) {
271- let mut lock = local. get( & type_url) ;
272-
273- // Remove any resources the upstream server has removed/doesn't have,
274- // we do this before applying any new/updated resources in case a
275- // resource is in both lists, though really that would be a bug in
276- // the upstream server
277- for removed in response. removed_resources {
278- lock. remove( & removed) ;
279- }
280-
281- for ( k, v) in version_map {
282- lock. insert( k, v) ;
283- }
293+ local. update_versions( & type_url, & response. removed_resources, version_map) ;
284294 }
285295
286296 res
0 commit comments