docs: def override_parent_subgraph(self, parent_subgraph, invisible_edges=None):
          """
          Get all items with outcoming edges from the given subgraph, drop all
          their parent relations, and then add parents according to the given
          subgraph.
  
          Args:
              parent_subgraph (dict): item id -> list of parents(item ids)
              invisible_edges (list|set): set of (from, to) tuples specifying
                  invisible edges
          """
          with transaction.atomic():
              if invisible_edges is None:
                  invisible_edges = set()
              children = list(parent_subgraph.keys())
              all_old_relations = dict(proso.list.group_by(
                  list(ItemRelation.objects.filter(child_id__in=children)),
                  by=lambda relation: relation.child_id
              ))
              to_delete = set()
              for child_id, parents in parent_subgraph.items():
                  old_relations = {
                      relation.parent_id: relation
                      for relation in all_old_relations.get(child_id, [])
                  }
                  for parent_id in parents:
                      if parent_id not in old_relations:
                          ItemRelation.objects.create(
                              parent_id=parent_id,
                              child_id=child_id,
                              visible=(child_id, parent_id) not in invisible_edges
                          )
                      elif old_relations[parent_id].visible != ((child_id, parent_id) not in invisible_edges):
                          old_relations[parent_id].visible = (child_id, parent_id) not in invisible_edges
                          old_relations[parent_id].save()
                  to_delete |= {old_relations[parent_id].pk for parent_id in set(old_relations.keys()) - set(parents)}
              ItemRelation.objects.filter(pk__in=to_delete).delete()