@@ -1156,11 +1156,40 @@ def feed_db_data(self, obj_data: Iterable[Any]) -> None:
11561156 pass
11571157
11581158
1159+ # Refetching links will only refetch linked objects which are already in the
1160+ # link, or are in the sync objects.
1161+ #
1162+ # A refetched object will therefore need, per link:
1163+ # - whether that link is being being refetched, and if so,
1164+ # - the objects already in the link.
1165+ #
1166+ # The order of links is kept consistent with the refetch shape.
1167+ RefetchSpecEntry = TypeAliasType (
1168+ "RefetchSpecEntry" ,
1169+ tuple [
1170+ uuid .UUID , # Refetched obj id
1171+ list [
1172+ tuple [
1173+ bool , # Whether the link is being refetched
1174+ list [uuid .UUID ], # Objects in the link
1175+ ]
1176+ ],
1177+ ],
1178+ )
1179+
1180+
1181+ @dataclasses .dataclass (kw_only = True , frozen = True )
1182+ class QueryRefetchArgs :
1183+ spec : list [RefetchSpecEntry ]
1184+ new : list [uuid .UUID ]
1185+ existing : list [uuid .UUID ]
1186+
1187+
11591188@_struct
11601189class QueryRefetch :
11611190 executor : SaveExecutor
11621191 query : TypeWrapper [type [GelModel ]]
1163- args : dict [ str , Any ]
1192+ args : QueryRefetchArgs
11641193 shape : RefetchShape
11651194
11661195 def feed_db_data (self , obj_data : Iterable [Any ]) -> None :
@@ -1305,7 +1334,7 @@ def _compile_refetch(
13051334 tuple [
13061335 type [GelModel ],
13071336 TypeWrapper [type [GelModel ]],
1308- list [Any ],
1337+ list [RefetchSpecEntry ],
13091338 RefetchShape ,
13101339 ]
13111340 ]:
@@ -1411,7 +1440,7 @@ def _compile_refetch(
14111440 else :
14121441 obj_link_ids .append (self ._get_id (s_link ))
14131442
1414- spec_arg = [
1443+ spec_arg : list [ RefetchSpecEntry ] = [
14151444 (
14161445 obj_id ,
14171446 [
@@ -1469,11 +1498,11 @@ def get_refetch_queries(
14691498 QueryRefetch (
14701499 executor = self ,
14711500 query = q [1 ],
1472- args = {
1473- " spec" : q [2 ],
1474- " new" : new_ids ,
1475- " existing" : list (self .existing_objects ),
1476- } ,
1501+ args = QueryRefetchArgs (
1502+ spec = q [2 ],
1503+ new = new_ids ,
1504+ existing = list (self .existing_objects ),
1505+ ) ,
14771506 shape = q [3 ],
14781507 )
14791508 for q in self ._compile_refetch ()
0 commit comments