Skip to content

Commit

Permalink
Batch indexing on version creation and reference delete
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Mar 10, 2021
1 parent b22d7c5 commit 0fbd64a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ def delete_references(self, expressions):

from core.concepts.documents import ConceptDocument
from core.mappings.documents import MappingDocument
ConceptDocument().update(Concept.objects.filter(uri__in=expressions))
MappingDocument().update(Mapping.objects.filter(uri__in=expressions))
self.batch_index(Concept.objects.filter(uri__in=expressions), ConceptDocument)
self.batch_index(Mapping.objects.filter(uri__in=expressions), MappingDocument)

@staticmethod
def __get_children_from_expressions(expressions):
Expand Down
21 changes: 16 additions & 5 deletions core/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def seed_concepts(self, index=True):
self.concepts.set(concepts)
if index:
from core.concepts.documents import ConceptDocument
ConceptDocument().update(self.concepts.all(), parallel=True)
self.batch_index(self.concepts, ConceptDocument)

def seed_mappings(self, index=True):
head = self.head
Expand All @@ -657,14 +657,25 @@ def seed_mappings(self, index=True):
self.mappings.set(mappings)
if index:
from core.mappings.documents import MappingDocument
MappingDocument().update(self.mappings.all(), parallel=True)
self.batch_index(self.mappings, MappingDocument)

@staticmethod
def batch_index(queryset, document):
count = queryset.count()
batch_size = 100
offset = 0
limit = batch_size
while offset < count:
document().update(queryset.all()[offset:limit], parallel=True)
offset = limit
limit += batch_size

def index_children(self):
from core.concepts.documents import ConceptDocument
ConceptDocument().update(self.concepts.all(), parallel=True)

from core.mappings.documents import MappingDocument
MappingDocument().update(self.mappings.all(), parallel=True)

self.batch_index(self.concepts, ConceptDocument)
self.batch_index(self.mappings, MappingDocument)

def add_processing(self, process_id):
if self.id:
Expand Down

0 comments on commit 0fbd64a

Please sign in to comment.