Skip to content

Commit

Permalink
[FEAT] Query instances in batches (#23)
Browse files Browse the repository at this point in the history
* feat ⭐ use batch query

* fix 🔧 make batch size a setting
  • Loading branch information
samar-hassan authored Apr 19, 2024
1 parent 5fa8576 commit 52cd434
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion oscar_odin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from django.db import connection, connections, reset_queries
from django.db.models import Q
from django.conf import settings

from odin.exceptions import ValidationError
from odin.mapping import MappingResult
Expand Down Expand Up @@ -41,7 +42,7 @@ def in_bulk(self, instances, field_names):
if max_query_params is not None:
batch_size = math.floor(max_query_params / len(field_names)) - 1
else:
batch_size = None
batch_size = getattr(settings, "ODIN_BATCH_SIZE", 500)

if batch_size and batch_size < len(instances):
qs = ()
Expand Down

0 comments on commit 52cd434

Please sign in to comment.