Skip to content

Commit

Permalink
backend: speeding up get_index for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
slaporte committed Oct 8, 2017
1 parent 2405e9d commit 2a5298d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion montage/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,6 @@ Abbreviated information about a round for a coordinator:
- `cancelled` (basically, it's deleted)
- `finalized` (all done)
- `config`: a dictionary of various settings for the round
- `is_closable`: this is true if the round has all the votes necessary to advance to the next round. For ranking rounds, you cannot preview results until all the ballots are submitted.

## round details
Complete information about a round for a coordinator (similar to [`juror round details`](#juror-round-details):
Expand Down
19 changes: 10 additions & 9 deletions montage/rdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,18 @@ def _get_rdb_session(self):
return rdb_session


def _get_open_task_count(self):
rdb_session = self._get_rdb_session()
def _get_open_task_count(self, rdb_session=None):
if not rdb_session:
rdb_session = self._get_rdb_session()
ret = (rdb_session.query(Vote)
.filter(Vote.round_entry.has(round_id=self.id),
Vote.status == ACTIVE_STATUS)
.count())
return ret

def _get_task_count(self):
rdb_session = self._get_rdb_session()
def _get_task_count(self, rdb_session=None):
if not rdb_session:
rdb_session = self._get_rdb_session()
ret = (rdb_session.query(Vote)
.filter(Vote.round_entry.has(round_id=self.id),
Vote.status != CANCELLED_STATUS)
Expand All @@ -336,8 +338,8 @@ def get_count_map(self):
rdb_session = self._get_rdb_session()
re_count = len(self.round_entries)

open_task_count = self._get_open_task_count()
task_count = self._get_task_count()
open_task_count = self._get_open_task_count(rdb_session=rdb_session)
task_count = self._get_task_count(rdb_session=rdb_session)
cancelled_task_count = rdb_session.query(Vote)\
.filter(Vote.round_entry.has(round_id=self.id),
Vote.status == CANCELLED_STATUS)\
Expand Down Expand Up @@ -400,7 +402,6 @@ def is_closeable(self):
return not active_votes
return False


def to_info_dict(self):
ret = {'id': self.id,
'name': self.name,
Expand All @@ -413,12 +414,12 @@ def to_info_dict(self):
'jurors': [rj.to_info_dict() for rj in self.round_jurors],
'status': self.status,
'config': self.config,
'round_sources': [],
'is_closable': self.check_closability()}
'round_sources': []}
return ret

def to_details_dict(self):
ret = self.to_info_dict()
ret['is_closable'] = self.check_closability()
ret['campaign'] = self.campaign.to_info_dict()
ret['quorum'] = self.quorum
ret['total_round_entries'] = len(self.round_entries)
Expand Down

0 comments on commit 2a5298d

Please sign in to comment.