|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +from collections import defaultdict |
3 | 4 | from collections.abc import Iterable
|
4 | 5 | from typing import TYPE_CHECKING, Any
|
5 | 6 |
|
6 | 7 | from ..exceptions import (
|
| 8 | + Error, |
7 | 9 | UninitializedError,
|
8 | 10 | )
|
| 11 | +from ..types import Order |
9 | 12 | from .constants import PROPERTIES_FLAG, PROPERTIES_OBJECT
|
10 | 13 | from .related_node import RelatedNode, RelatedNodeSync
|
11 | 14 |
|
@@ -156,8 +159,29 @@ async def fetch(self) -> None:
|
156 | 159 | self.peers = rm.peers
|
157 | 160 | self.initialized = True
|
158 | 161 |
|
| 162 | + ids_per_kind_map = defaultdict(list) |
159 | 163 | for peer in self.peers:
|
160 |
| - await peer.fetch() # type: ignore[misc] |
| 164 | + if not peer.id or not peer.typename: |
| 165 | + raise Error("Unable to fetch the peer, id and/or typename are not defined") |
| 166 | + if peer.typename not in ids_per_kind_map: |
| 167 | + ids_per_kind_map[peer.typename] = [peer.id] |
| 168 | + else: |
| 169 | + ids_per_kind_map[peer.typename].append(peer.id) |
| 170 | + |
| 171 | + batch = await self.client.create_batch() |
| 172 | + for kind, ids in ids_per_kind_map.items(): |
| 173 | + batch.add( |
| 174 | + task=self.client.filters, |
| 175 | + kind=kind, |
| 176 | + ids=ids, |
| 177 | + populate_store=True, |
| 178 | + branch=self.branch, |
| 179 | + parallel=True, |
| 180 | + order=Order(disable=True), |
| 181 | + ) |
| 182 | + |
| 183 | + async for _ in batch.execute(): |
| 184 | + pass |
161 | 185 |
|
162 | 186 | def add(self, data: str | RelatedNode | dict) -> None:
|
163 | 187 | """Add a new peer to this relationship."""
|
@@ -261,8 +285,29 @@ def fetch(self) -> None:
|
261 | 285 | self.peers = rm.peers
|
262 | 286 | self.initialized = True
|
263 | 287 |
|
| 288 | + ids_per_kind_map = defaultdict(list) |
264 | 289 | for peer in self.peers:
|
265 |
| - peer.fetch() |
| 290 | + if not peer.id or not peer.typename: |
| 291 | + raise Error("Unable to fetch the peer, id and/or typename are not defined") |
| 292 | + if peer.typename not in ids_per_kind_map: |
| 293 | + ids_per_kind_map[peer.typename] = [peer.id] |
| 294 | + else: |
| 295 | + ids_per_kind_map[peer.typename].append(peer.id) |
| 296 | + |
| 297 | + batch = self.client.create_batch() |
| 298 | + for kind, ids in ids_per_kind_map.items(): |
| 299 | + batch.add( |
| 300 | + task=self.client.filters, |
| 301 | + kind=kind, |
| 302 | + ids=ids, |
| 303 | + populate_store=True, |
| 304 | + branch=self.branch, |
| 305 | + parallel=True, |
| 306 | + order=Order(disable=True), |
| 307 | + ) |
| 308 | + |
| 309 | + for _ in batch.execute(): |
| 310 | + pass |
266 | 311 |
|
267 | 312 | def add(self, data: str | RelatedNodeSync | dict) -> None:
|
268 | 313 | """Add a new peer to this relationship."""
|
|
0 commit comments