7
7
import typing as t
8
8
9
9
from .config import conf
10
- from .transport import Count , Get , runSingleFilter
10
+ from .transport import Count , Get , run_single_filter
11
11
from .types import (
12
12
DATASTORE_BASE_TYPES ,
13
13
Entity ,
17
17
TFilters ,
18
18
TOrders ,
19
19
)
20
- from .utils import IsInTransaction
20
+ from . import utils
21
21
22
22
if t .TYPE_CHECKING :
23
23
from viur .core .skeleton import SkeletonInstance , SkelList
@@ -444,39 +444,38 @@ def getKind(self) -> str:
444
444
"""
445
445
return self .kind
446
446
447
- def _runSingleFilterQuery (self , query : QueryDefinition , limit : int ) -> t .List [Entity ]:
447
+ def _run_single_filter_query (self , query : QueryDefinition , limit : int ) -> t .List [Entity ]:
448
448
"""
449
449
Internal helper function that runs a single query definition on the datastore and returns a list of
450
450
entities found.
451
451
:param query: The querydefinition (filters, orders, distinct etc.) to run against the datastore
452
452
:param limit: How many results should at most be returned
453
453
:return: The first *limit* entities that matches this query
454
454
"""
455
- return runSingleFilter (query , limit )
455
+ return run_single_filter (query , limit )
456
456
457
- def _mergeMultiQueryResults (self , inputRes : t .List [t .List [Entity ]]) -> t .List [Entity ]:
457
+ def _merge_multi_query_results (self , input_result : t .List [t .List [Entity ]]) -> t .List [Entity ]:
458
458
"""
459
459
Merge the lists of entries into a single list; removing duplicates and restoring sort-order
460
- :param inputRes : Nested Lists of Entries returned by each individual query run
460
+ :param input_result : Nested Lists of Entries returned by each individual query run
461
461
:return: Sorted & deduplicated list of entries
462
462
"""
463
- seenKeys = set ()
463
+ seen_keys = set ()
464
464
res = []
465
- for subList in inputRes :
465
+ for subList in input_result :
466
466
for entry in subList :
467
467
key = entry .key
468
- if key in seenKeys :
468
+ if key in seen_keys :
469
469
continue
470
- seenKeys .add (key )
470
+ seen_keys .add (key )
471
471
res .append (entry )
472
472
# FIXME: What about filters that mix different inequality filters?
473
473
# Currently, we'll now simply ignore any implicit sortorder.
474
- return self ._resortResult (res , {}, self .queries [0 ].orders )
474
+ return self ._resort_result (res , {}, self .queries [0 ].orders )
475
475
476
- def _resortResult (
476
+ def _resort_result (
477
477
self ,
478
- entities :
479
- t .List [Entity ],
478
+ entities : t .List [Entity ],
480
479
filters : t .Dict [str , DATASTORE_BASE_TYPES ],
481
480
orders : t .List [t .Tuple [str , SortOrder ]],
482
481
) -> t .List [Entity ]:
@@ -578,7 +577,7 @@ def run(self, limit: int = -1) -> t.List[Entity]:
578
577
return []
579
578
580
579
if self ._fulltextQueryString :
581
- if IsInTransaction ():
580
+ if utils . is_in_transaction ():
582
581
raise ValueError ("Can't run fulltextSearch inside transactions!" ) # InvalidStateError FIXME!
583
582
qryStr = self ._fulltextQueryString
584
583
self ._fulltextQueryString = None # Reset, so the adapter can still work with this query
@@ -596,17 +595,17 @@ def run(self, limit: int = -1) -> t.List[Entity]:
596
595
res = []
597
596
# We run all queries first (preventing multiple round-trips to the server)
598
597
for singleQuery in self .queries :
599
- res .append (self ._runSingleFilterQuery (singleQuery , limit if limit != - 1 else singleQuery .limit ))
598
+ res .append (self ._run_single_filter_query (singleQuery , limit if limit != - 1 else singleQuery .limit ))
600
599
# Wait for the actual results to arrive and convert the protobuffs to Entries
601
600
res = [self ._fixKind (x ) for x in res ]
602
601
if self ._customMultiQueryMerge :
603
602
# We have a custom merge function, use that
604
603
res = self ._customMultiQueryMerge (self , res , limit if limit != - 1 else self .queries [0 ].limit )
605
604
else :
606
605
# We must merge (and sort) the results ourself
607
- res = self ._mergeMultiQueryResults (res )
606
+ res = self ._merge_multi_query_results (res )
608
607
else : # We have just one single query
609
- res = self ._fixKind (self ._runSingleFilterQuery (self .queries , limit if limit != - 1 else self .queries .limit ))
608
+ res = self ._fixKind (self ._run_single_filter_query (self .queries , limit if limit != - 1 else self .queries .limit ))
610
609
if res :
611
610
self ._lastEntry = res [- 1 ]
612
611
return res
@@ -688,7 +687,7 @@ def iter(self) -> t.Iterator[Entity]:
688
687
elif isinstance (self .queries , list ):
689
688
raise ValueError ("No iter on Multiqueries" )
690
689
while True :
691
- qryRes = self ._runSingleFilterQuery (self .queries , 20 )
690
+ qryRes = self ._run_single_filter_query (self .queries , 20 )
692
691
yield from qryRes
693
692
if not self .queries .currentCursor : # We reached the end of that query
694
693
break
0 commit comments