Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/vfbquery/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
cache's version stamp can never drift apart.
"""

__version__ = "1.22.24"
__version__ = "1.22.25"
18 changes: 16 additions & 2 deletions src/vfbquery/solr_result_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,18 @@ def wrapper(*args, **kwargs):
limit = kwargs.get('limit', -1)
should_cache = (limit == -1) # Only cache when getting all results (limit=-1)
offset = kwargs.get('offset', 0) or 0 # page start for slicing cached FULL results (0 keeps the cached full set complete)
# The wrapper does all offset slicing itself (via the `offset` local
# above); the wrapped func only ever computes the FULL result. Some
# funcs declare `offset` (native SKIP paging), most do not. Never leak
# `offset` into a func that can't accept it, or a cold cache miss 500s
# (e.g. get_similar_neurons: 'unexpected keyword argument offset').
try:
import inspect as _inspect_off
_func_takes_offset = 'offset' in _inspect_off.signature(func).parameters
except (ValueError, TypeError):
_func_takes_offset = False
if not _func_takes_offset:
kwargs.pop('offset', None)

# For expensive queries, we still only cache full results, but we handle limited requests
# by slicing from cached full results
Expand Down Expand Up @@ -1109,7 +1121,8 @@ def wrapper(*args, **kwargs):
# do one full call, cache it, then slice for return.
full_kwargs = kwargs.copy()
full_kwargs['limit'] = -1
full_kwargs['offset'] = 0
if _func_takes_offset:
full_kwargs['offset'] = 0
full_result = func(*args, **full_kwargs)
else:
full_result = func(*args, **kwargs)
Expand Down Expand Up @@ -1166,7 +1179,8 @@ def wrapper(*args, **kwargs):
import inspect
if 'limit' in inspect.signature(func).parameters:
full_kwargs['limit'] = -1
full_kwargs['offset'] = 0
if _func_takes_offset:
full_kwargs['offset'] = 0
# print(f"DEBUG: Executing {query_type} with full results for caching")
full_result = func(*args, **full_kwargs)
result = full_result
Expand Down
Loading
Loading