Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use lazyloading when query is paginated #247

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion xivo_dao/resources/user/persistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def count_all_by(self, column_name, criteria):
return query.all()

def _search(self, parameters, is_collated=False):
view = self.user_view.select(parameters.get('view'))
selected_view = parameters.get('view')
if not selected_view:
limit = parameters.get('limit') or 0
if 0 < limit < 101:
selected_view = 'paginated'
view = self.user_view.select(selected_view)
query = view.query(self.session)
if self.tenant_uuids is not None:
query = query.filter(User.tenant_uuid.in_(self.tenant_uuids))
Expand Down
10 changes: 9 additions & 1 deletion xivo_dao/resources/user/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
from xivo_dao.alchemy.user_line import UserLine


class PaginatedView(View):
def query(self, session):
return session.query(User)

def convert(self, model):
return model


class UserView(View):
def query(self, session):
return session.query(User).options(
Expand Down Expand Up @@ -137,5 +145,5 @@ def convert(self, row):


user_view = ViewSelector(
default=UserView(), directory=DirectoryView(), summary=SummaryView()
default=UserView(), directory=DirectoryView(), summary=SummaryView(), paginated=PaginatedView(),
)