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

Revert db.session.query #1846

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
6 changes: 2 additions & 4 deletions pay-api/src/pay_api/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ def search_purchase_history( # noqa:E501; pylint:disable=too-many-arguments, to
if not return_all:
count_future = executor.submit(cls.get_count, auth_account_id, search_filter)
sub_query = cls.generate_subquery(auth_account_id, search_filter, limit, page)
# Need to do it this way otherwise doesn't know how to join for the subquery for some reason.
invoice_ids = {item for t in sub_query.all() for item in t}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work with > 65535 rows

query = query.filter(Invoice.id.in_(invoice_ids)).order_by(Invoice.id.desc())
query = query.filter(Invoice.id.in_(sub_query.subquery().select())).order_by(Invoice.id.desc())
result_future = executor.submit(db.session.query(Invoice).from_statement(query).all)
count = count_future.result()
result = result_future.result()
Expand Down Expand Up @@ -518,7 +516,7 @@ def generate_subquery(cls, auth_account_id, search_filter, limit, page):
subquery = subquery.limit(limit)
if limit and page:
subquery = subquery.offset((page - 1) * limit)
return db.session.query(subquery.subquery())
return subquery


class PaymentSchema(BaseSchema): # pylint: disable=too-many-ancestors
Expand Down