Skip to content
Snippets Groups Projects
Commit 80c0a817 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'remove-get-descendings' into 'master'

Remove unused ElementManager.get_descendings

See merge request !1604
parents 47b27803 f2e1e2e9
No related branches found
No related tags found
1 merge request!1604Remove unused ElementManager.get_descendings
import uuid
from itertools import chain
import django
......@@ -127,38 +126,6 @@ class ElementManager(models.Manager):
"""
return self.filter(paths__path__contains=[parent_id], **filters).order_by('paths__ordering').distinct()
def get_descendings(self, parents_ids, prefetch=(), **filters):
"""
Get all child elements for some element IDs.
"""
assert all(isinstance(x, uuid.UUID) for x in parents_ids), 'UUIDs are required'
# Loads paths and group them by element ids
# The map to str is needed to avoid a cast error in PG
from arkindex.documents.models import ElementPath
paths = ElementPath.objects.filter(path__overlap=map(str, parents_ids)).order_by('element_id', 'ordering')
tree = {
parent_id: [
p.element_id
for p in paths
if parent_id in p.path
]
for parent_id in parents_ids
}
# Load children elements in bulk
children = self.filter(id__in=[p.element_id for p in paths], **filters)
if prefetch:
children = children.prefetch_related(*prefetch)
return {
parent_id: [
child
for child in children
if child.id in tree.get(parent_id)
]
for parent_id in parents_ids
}
def get_neighbor_paths(self, element, n=1):
"""
Get n neighbor paths: current, previous and next element paths
......
......@@ -38,13 +38,6 @@ class TestElementManager(FixtureTestCase):
ids = Element.objects.get_descending(self.p2.id)
self.assertCountEqual(ids, [])
def test_get_descendings(self):
# Use all pages, expect Act and nothing else
ids = Element.objects.get_descendings([self.p1.id, self.p2.id, self.p3.id])
self.assertCountEqual(ids[self.p1.id], [self.act])
self.assertCountEqual(ids[self.p2.id], [])
self.assertCountEqual(ids[self.p3.id], [])
def test_get_neighbors(self):
with self.assertNumQueries(4):
self.assertEqual(len(Element.objects.get_neighbors(self.p1, 0)), 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment