@@ -116,26 +116,30 @@ def apply_delta(self, collections: Collections):
116116 Applies a delta update to the store.
117117 """
118118 try :
119- self . _lock . lock ()
119+ all_decoded = {}
120120 for kind in collections :
121121 collection = collections [kind ]
122+ items_decoded = {}
122123 for key in collection :
123- self .__upsert (kind , collection [key ])
124+ items_decoded [key ] = kind .decode (collection [key ])
125+ all_decoded [kind ] = items_decoded
126+ except Exception as e :
127+ log .error ("Failed decoding apply_delta collection. Aborting" , exc_info = e )
128+ return
129+
130+ try :
131+ self ._lock .lock ()
132+ for kind , kind_data in all_decoded .items ():
133+ items_of_kind = self ._items [kind ]
134+ kind_data = all_decoded [kind ]
135+ for key , item in kind_data .items ():
136+ items_of_kind [key ] = item
137+ log .debug (
138+ "Updated %s in '%s' to version %d" , key , kind .namespace , item ["version" ]
139+ )
124140 finally :
125141 self ._lock .unlock ()
126142
127- def __upsert (self , kind , item ):
128- """
129- Inserts or updates an item in the store.
130- """
131- decoded_item = kind .decode (item )
132- key = item ["key" ]
133- items_of_kind = self ._items [kind ]
134- items_of_kind [key ] = decoded_item
135- log .debug (
136- "Updated %s in '%s' to version %d" , key , kind .namespace , item ["version" ]
137- )
138-
139143 @property
140144 def initialized (self ) -> bool :
141145 """
0 commit comments