Loading resources/models.py +3 −24 Changes for resources/models.py: 3 added lines, 24 removed lines. Original line number Diff line number Diff line from django.db.models.query import RawQuerySet from django.utils.text import slugify from django.db import models, connection from django.contrib.auth.models import User Loading Loading @@ -559,33 +558,15 @@ class Collection(models.Model): def children(self): return Collection.objects.filter(parent=self, deleted_at__isnull=True) def descendants(self) -> Union[RawQuerySet, Iterator["Collection"]]: if settings.JAMA_SQLITE_DB_PATH: def descendants(self) -> Iterator["Collection"]: yield from _recurse_collection(self) else: return Collection.objects.raw( "select * from resources_collection where id = any(get_all_collection_descendants_array(%s)) and deleted_at is null", [self.id], ) def descendants_resources(self) -> Union[RawQuerySet, Iterator[Resource]]: if settings.JAMA_SQLITE_DB_PATH: def descendants_resources(self) -> Iterator[Resource]: for res in self.resources.filter(deleted_at__isnull=True): yield res for col in _recurse_collection(self): for res in col.resources.filter(deleted_at__isnull=True): yield res else: sql = """ select * from resources_resource inner join resources_collectionmembership rc on resources_resource.id = rc.resource_id inner join resources_collection c on rc.collection_id = c.id where rc.collection_id = any(get_all_collection_descendants_array(%s)) and c.deleted_at is null and resources_resource.deleted_at is null order by resources_resource.title; """ return Resource.objects.raw(sql, [self.id]) def descendants_and_self_ids(self) -> List[int]: ids = [self.pk] Loading Loading @@ -768,9 +749,7 @@ class Collection(models.Model): .prefetch_related("metadataresourcevalue_set") ): yield _flatten_resource(res, known_metadatas, known_metadatas_labels) for res in self.descendants_resources().prefetch_related( "metadataresourcevalue_set" ): for res in self.descendants_resources(): yield _flatten_resource(res, known_metadatas, known_metadatas_labels) Loading Loading
resources/models.py +3 −24 Changes for resources/models.py: 3 added lines, 24 removed lines. Original line number Diff line number Diff line from django.db.models.query import RawQuerySet from django.utils.text import slugify from django.db import models, connection from django.contrib.auth.models import User Loading Loading @@ -559,33 +558,15 @@ class Collection(models.Model): def children(self): return Collection.objects.filter(parent=self, deleted_at__isnull=True) def descendants(self) -> Union[RawQuerySet, Iterator["Collection"]]: if settings.JAMA_SQLITE_DB_PATH: def descendants(self) -> Iterator["Collection"]: yield from _recurse_collection(self) else: return Collection.objects.raw( "select * from resources_collection where id = any(get_all_collection_descendants_array(%s)) and deleted_at is null", [self.id], ) def descendants_resources(self) -> Union[RawQuerySet, Iterator[Resource]]: if settings.JAMA_SQLITE_DB_PATH: def descendants_resources(self) -> Iterator[Resource]: for res in self.resources.filter(deleted_at__isnull=True): yield res for col in _recurse_collection(self): for res in col.resources.filter(deleted_at__isnull=True): yield res else: sql = """ select * from resources_resource inner join resources_collectionmembership rc on resources_resource.id = rc.resource_id inner join resources_collection c on rc.collection_id = c.id where rc.collection_id = any(get_all_collection_descendants_array(%s)) and c.deleted_at is null and resources_resource.deleted_at is null order by resources_resource.title; """ return Resource.objects.raw(sql, [self.id]) def descendants_and_self_ids(self) -> List[int]: ids = [self.pk] Loading Loading @@ -768,9 +749,7 @@ class Collection(models.Model): .prefetch_related("metadataresourcevalue_set") ): yield _flatten_resource(res, known_metadatas, known_metadatas_labels) for res in self.descendants_resources().prefetch_related( "metadataresourcevalue_set" ): for res in self.descendants_resources(): yield _flatten_resource(res, known_metadatas, known_metadatas_labels) Loading