List all objects and populate the cache, firing ADDED/MODIFIED/DELETED events. On the first call (empty cache) every returned item fires ADDED. On subsequent calls (resync or after a 410 Gone) the new list is diffed against the existing cache: * Items absent from the
(self)
| 190 | ) |
| 191 | |
| 192 | def _initial_list(self): |
| 193 | """List all objects and populate the cache, firing ADDED/MODIFIED/DELETED events. |
| 194 | |
| 195 | On the first call (empty cache) every returned item fires ADDED. |
| 196 | On subsequent calls (resync or after a 410 Gone) the new list is |
| 197 | diffed against the existing cache: |
| 198 | * Items absent from the new list fire DELETED. |
| 199 | * Items present in both fire MODIFIED. |
| 200 | * Items only in the new list fire ADDED. |
| 201 | """ |
| 202 | kw = self._build_kwargs() |
| 203 | resp = self._list_func(**kw) |
| 204 | items = getattr(resp, "items", []) or [] |
| 205 | |
| 206 | # Build key → item map for incoming items. |
| 207 | new_items_map = {} |
| 208 | for item in items: |
| 209 | key = self._cache._key_func(item) |
| 210 | new_items_map[key] = item |
| 211 | |
| 212 | # Snapshot the old keys before replacing the cache. |
| 213 | old_keys = set(self._cache.list_keys()) |
| 214 | |
| 215 | # Fire DELETED for items no longer present in the new list. |
| 216 | for key in old_keys: |
| 217 | if key not in new_items_map: |
| 218 | old_obj = self._cache.get_by_key(key) |
| 219 | if old_obj is not None: |
| 220 | self._fire(DELETED, old_obj) |
| 221 | |
| 222 | # Atomically replace the cache. |
| 223 | self._cache._replace_all(items) |
| 224 | |
| 225 | # Fire ADDED for genuinely new items, MODIFIED for existing ones. |
| 226 | for key, item in new_items_map.items(): |
| 227 | if key in old_keys: |
| 228 | self._fire(MODIFIED, item) |
| 229 | else: |
| 230 | self._fire(ADDED, item) |
| 231 | |
| 232 | rv = None |
| 233 | meta = getattr(resp, "metadata", None) |
| 234 | if meta is not None: |
| 235 | rv = getattr(meta, "resource_version", None) |
| 236 | self._resource_version = rv or "0" |
| 237 | |
| 238 | def _run_loop(self): |
| 239 | """Background loop: list then watch, reconnect on errors. |
no test coverage detected