Skip to content

Commit

Permalink
fixes #557 - breaks up query results
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinwan committed Aug 11, 2015
1 parent d476a9e commit b332dbd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
3 changes: 3 additions & 0 deletions server/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
STAFF_ROLE = 'staff'
VALID_ROLES = [STUDENT_ROLE, STAFF_ROLE]
GRADES_BUCKET = 'ok_grades_bucket'

# submission downloads
BATCH_SIZE = 25
32 changes: 23 additions & 9 deletions server/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datetime
import itertools
from os.path import join
from app import constants

try:
from cStringIO import StringIO
Expand Down Expand Up @@ -563,16 +564,29 @@ def make_zip_filename(user, now):
return filename+'.zip'


def subms_to_gcs(SearchAPI, SubmissionAPI, Submission, user, data, datetime):
"""
Writes all submissions for a given search query
to a GCS zip file.
"""
results = SearchAPI.results(data)
def make_query(SearchAPI, data, start_cursor):
"""Creates query at cursor if specified"""
query = SearchAPI.querify(data['query'])

if start_cursor:
query.with_cursor(start_cursor)

return query


def subms_to_gcs(SearchAPI, SubmissionAPI, Submission, user, data, datetime,
start_cursor=None):
"""Writes all submissions for a given search query to a GCS zip file."""
query = make_query(SearchAPI, data, start_cursor)
zipfile_str, zipfile = start_zip()
subm = SubmissionAPI()
for result in results:
zipfile = add_subm_to_zip(subm, Submission, zipfile, result)
subm, i = SubmissionAPI(), 0
for result in query:
zipfile, i = add_subm_to_zip(subm, Submission, zipfile, result), i + 1
if i == constants.BATCH_SIZE:
start_cursor = query.cursor()
deferred.defer(subms_to_gcs, SearchAPI, SubmissionAPI, Submission,
user, data, datetime, start_cursor)
return
zip_contents = finish_zip(zipfile_str, zipfile)
zip_filename = make_zip_filename(user, datetime)
create_gcs_file(zip_filename, zip_contents, 'application/zip')
12 changes: 6 additions & 6 deletions server/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ indexes:
- name: created
direction: desc

- kind: Backupv2
properties:
- name: assignment
- name: created
direction: desc

- kind: Backupv2
properties:
- name: assignment
Expand Down Expand Up @@ -259,9 +265,3 @@ indexes:
properties:
- name: email
- name: status

- kind: Backupv2
properties:
- name: assignment
- name: created
direction: desc

0 comments on commit b332dbd

Please sign in to comment.