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

Fix elections endpoint to handle per_page=0 #3303

Merged
merged 1 commit into from
Jul 24, 2018
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
14 changes: 14 additions & 0 deletions webservices/resources/elections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from webservices import utils
from webservices import filters
from webservices import schemas
from webservices.common import counts
from webservices.utils import use_kwargs
from webservices.common import models
from webservices.common.views import ApiResource
Expand Down Expand Up @@ -128,6 +129,19 @@ def args(self):
),
)

def get(self, *args, **kwargs):
query = self.build_query(*args, **kwargs)
count = counts.count_estimate(query, models.db.session, threshold=500000)
Copy link
Contributor

@pkfec pkfec Jul 24, 2018

Choose a reason for hiding this comment

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

Any reason why the threshold is set to high value?

multi = False
if isinstance(kwargs['sort'], (list, tuple)):
multi = True

return utils.fetch_page(
query, kwargs,
count=count, model=self.model, join_columns=self.join_columns, aliases=self.aliases,
index_column=self.index_column, cap=0, multi=multi,
)

def build_query(self, **kwargs):
utils.check_election_arguments(kwargs)
totals_model = office_totals_map[kwargs['office']]
Expand Down