Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions weaviate/collections/iterator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import deque
from dataclasses import dataclass
from typing import (
Any,
Expand Down Expand Up @@ -54,14 +55,14 @@ def __init__(
self.__query = query
self.__inputs = inputs

self.__iter_object_cache: List[Object[TProperties, TReferences]] = []
self.__iter_object_cache: deque[Object[TProperties, TReferences]] = deque()
self.__iter_object_last_uuid: Optional[UUID] = _parse_after(self.__inputs.after)
self.__iter_cache_size = cache_size or ITERATOR_CACHE_SIZE

def __iter__(
self,
) -> Iterator[Object[TProperties, TReferences]]:
self.__iter_object_cache = []
self.__iter_object_cache = deque()
self.__iter_object_last_uuid = _parse_after(self.__inputs.after)
return self

Expand All @@ -75,11 +76,11 @@ def __next__(self) -> Object[TProperties, TReferences]:
return_properties=self.__inputs.return_properties,
return_references=self.__inputs.return_references,
)
self.__iter_object_cache = res.objects # type: ignore
self.__iter_object_cache = deque(res.objects) # type: ignore
if len(self.__iter_object_cache) == 0:
raise StopIteration

ret_object = self.__iter_object_cache.pop(0)
ret_object = self.__iter_object_cache.popleft()
self.__iter_object_last_uuid = ret_object.uuid
assert (
self.__iter_object_last_uuid is not None
Expand All @@ -100,14 +101,14 @@ def __init__(
self.__query = query
self.__inputs = inputs

self.__iter_object_cache: List[Object[TProperties, TReferences]] = []
self.__iter_object_cache: deque[Object[TProperties, TReferences]] = deque()
self.__iter_object_last_uuid: Optional[UUID] = _parse_after(self.__inputs.after)
self.__iter_cache_size = cache_size or ITERATOR_CACHE_SIZE

def __aiter__(
self,
) -> AsyncIterator[Object[TProperties, TReferences]]:
self.__iter_object_cache = []
self.__iter_object_cache = deque()
self.__iter_object_last_uuid = _parse_after(self.__inputs.after)
return self

Expand All @@ -123,11 +124,11 @@ async def __anext__(
return_properties=self.__inputs.return_properties,
return_references=self.__inputs.return_references,
)
self.__iter_object_cache = res.objects # type: ignore
self.__iter_object_cache = deque(res.objects) # type: ignore
if len(self.__iter_object_cache) == 0:
raise StopAsyncIteration

ret_object = self.__iter_object_cache.pop(0)
ret_object = self.__iter_object_cache.popleft()
self.__iter_object_last_uuid = ret_object.uuid
assert (
self.__iter_object_last_uuid is not None
Expand Down