Skip to content

Commit

Permalink
mibios/query: remove superceeded QuerySet methods
Browse files Browse the repository at this point in the history
  • Loading branch information
robert102 committed Nov 20, 2024
1 parent b0a7700 commit 8f6d811
Showing 1 changed file with 0 additions and 77 deletions.
77 changes: 0 additions & 77 deletions mibios/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,80 +1016,3 @@ def iterate(self, chunk_size=None, cache=None):
return ModelIterable(self, chunk_size, cache)
else:
return ValuesListIterable(self, chunk_size, cache)

def _iterate_model(self, chunk_size, cache):
""" iterate() implementation for normal model-based querysets """
if cache is True:
# auto-caching-mode
# TODO: pick up fields from only()?
cache = FKCache(self.model, fk_fields=None)

qs = self.order_by('pk')

last_pk = 0
while True:
chunk = qs.filter(pk__gt=last_pk)[:chunk_size]

if cache:
# update in-place
cache.update_chunk(chunk)

yield from chunk

if len(chunk) < chunk_size:
# no further results
break

last_pk = chunk[len(chunk) - 1].pk

def _iterate_values_list(self, chunk_size, cache):
""" iterate() implementation for values_list() querysets """
qs = self

outnames = qs.get_output_field_names()
hide_pk = False
try:
pk_pos = outnames.index(qs.model._meta.pk.name)
except ValueError:
if 'pk' in outnames:
pk_pos = outnames.index('pk')
else:
# we have to get PK to make chunking work
qs = qs.values_list('pk', *outnames)
pk_pos = 0
hide_pk = True

if cache is True:
# auto-caching-mode
fk_fields = []
for i in qs.model._meta.get_fields():
if not i.many_to_one:
continue
if i.name in outnames or i.attname in outnames:
fk_fields.append(i)
cache = FKCache(qs.model, fk_fields=fk_fields)

qs = qs.order_by('pk')

last_pk = 0
while True:
chunk = qs.filter(pk__gt=last_pk)[:chunk_size]

if cache:
# chunk is replaced, type is list now
chunk = cache.update_values_list(chunk)

# For non-empty chunk get last PK before they are removed. Must
# also avoid negative indexing in case chunk is queryset, so
# calculate last row via length.
if chunk_length := len(chunk):
last_pk = chunk[chunk_length - 1][pk_pos]

if hide_pk:
chunk = ((i[slice(1, None)] for i in chunk))

yield from chunk

if chunk_length < chunk_size:
# no further results
break

0 comments on commit 8f6d811

Please sign in to comment.