fix: dont use query for children total count
This commit is contained in:
@@ -65,7 +65,6 @@ class VGroups:
|
||||
if not ctx:
|
||||
raise NotImplementedError("Shouldn't happen, where is my context?")
|
||||
builder = ctx.build_state.builder
|
||||
# TODO: fix record_dependency -> process in non-capturing context
|
||||
GroupByRef.of(builder).make_once(keys) # ensure did cluster before use
|
||||
# find groups
|
||||
proc_list = [record]
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
from lektor import datamodel
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, Dict
|
||||
if TYPE_CHECKING:
|
||||
from lektor.environment import Environment
|
||||
from lektor.pagination import Pagination
|
||||
from lektor.sourceobj import SourceObject
|
||||
|
||||
|
||||
class PaginationConfig(datamodel.PaginationConfig):
|
||||
# because original method does not work for virtual sources.
|
||||
def __init__(self, env: 'Environment', config: Dict[str, Any], total: int):
|
||||
super().__init__(env, **config)
|
||||
self._total_items_count = total
|
||||
|
||||
@staticmethod
|
||||
def get_record_for_page(source: 'SourceObject', page_num: int) -> Any:
|
||||
for_page = getattr(source, '__for_page__', None)
|
||||
def get_record_for_page(record: 'SourceObject', page_num: int) -> Any:
|
||||
for_page = getattr(record, '__for_page__', None)
|
||||
if callable(for_page):
|
||||
return for_page(page_num)
|
||||
return datamodel.PaginationConfig.get_record_for_page(source, page_num)
|
||||
return datamodel.PaginationConfig.get_record_for_page(record, page_num)
|
||||
|
||||
def count_total_items(self, record: 'SourceObject') -> int:
|
||||
''' Override super() to prevent a record.children query. '''
|
||||
return self._total_items_count
|
||||
|
||||
if TYPE_CHECKING:
|
||||
def get_pagination_controller(self, source: 'SourceObject') \
|
||||
def get_pagination_controller(self, record: 'SourceObject') \
|
||||
-> 'Pagination':
|
||||
...
|
||||
|
||||
@@ -58,6 +58,11 @@ class FixedRecordsQuery(Query):
|
||||
return len(self.__child_paths)
|
||||
return super().count() # type: ignore[no-any-return]
|
||||
|
||||
@property
|
||||
def total(self) -> int:
|
||||
''' Return total entries count (without any filter). '''
|
||||
return len(self.__child_paths)
|
||||
|
||||
def get(self, path: str, page_num: Optional[int] = None) \
|
||||
-> Optional['Record']:
|
||||
''' Return Record with given path '''
|
||||
|
||||
@@ -100,7 +100,8 @@ class GroupBySource(VirtualSourceObject):
|
||||
@cached_property
|
||||
def _pagination_config(self) -> 'PaginationConfig':
|
||||
# Generate `PaginationConfig` once we need it
|
||||
return PaginationConfig(self.record.pad.env, **self.config.pagination)
|
||||
return PaginationConfig(self.record.pad.env, self.config.pagination,
|
||||
self._query.total)
|
||||
|
||||
@cached_property
|
||||
def pagination(self) -> 'Pagination':
|
||||
@@ -185,10 +186,10 @@ class GroupBySource(VirtualSourceObject):
|
||||
# Properties & Helper
|
||||
# -----------------------
|
||||
|
||||
@cached_property
|
||||
@property
|
||||
def children(self) -> FixedRecordsQuery:
|
||||
''' Return query of children of type Record. '''
|
||||
return self._query.request_page(self.page_num)
|
||||
return self._query
|
||||
|
||||
def __getitem__(self, key: str) -> Any:
|
||||
# Used for virtual path resolver
|
||||
|
||||
Reference in New Issue
Block a user