Skip to content

Commit

Permalink
Moving batch index logic in base model
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Jun 7, 2021
1 parent 0fcee7f commit 11573b4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions core/common/models.py
Expand Up @@ -157,6 +157,17 @@ def get_iexact_or_criteria(attr, values):

return criteria

@staticmethod
def batch_index(queryset, document):
count = queryset.count()
batch_size = 1000
offset = 0
limit = batch_size
while offset < count:
document().update(queryset.order_by('-id')[offset:limit], parallel=True)
offset = limit
limit += batch_size


class CommonLogoModel(models.Model):
logo_path = models.TextField(null=True, blank=True)
Expand Down Expand Up @@ -635,17 +646,6 @@ def seed_mappings(self, index=True):
from core.mappings.documents import MappingDocument
self.batch_index(self.mappings, MappingDocument)

@staticmethod
def batch_index(queryset, document):
count = queryset.count()
batch_size = 1000
offset = 0
limit = batch_size
while offset < count:
document().update(queryset.order_by('-id')[offset:limit], parallel=True)
offset = limit
limit += batch_size

def index_children(self):
from core.concepts.documents import ConceptDocument
from core.mappings.documents import MappingDocument
Expand Down

0 comments on commit 11573b4

Please sign in to comment.