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 File Size to Determine Whether To Do csv_import Asynchronously #1229

Merged
merged 1 commit into from
Feb 2, 2018
Merged
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
6 changes: 3 additions & 3 deletions onadata/apps/api/tests/viewsets/test_xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ def test_csv_import(self):
self.assertEqual(response.data.get('updates'), 0)

@override_settings(CELERY_ALWAYS_EAGER=True)
@override_settings(CSV_ROW_IMPORT_ASYNC_THRESHOLD=5)
@override_settings(CSV_FILESIZE_IMPORT_ASYNC_THRESHOLD=20)
def test_csv_import_async(self):
with HTTMock(enketo_mock):
xls_path = os.path.join(settings.PROJECT_ROOT, "apps", "main",
Expand Down Expand Up @@ -1902,7 +1902,7 @@ def test_csv_import_additional_columns(self):
@patch('onadata.apps.api.viewsets.xform_viewset.submit_csv_async')
def test_raise_error_when_task_is_none(self, mock_submit_csv_async):
with HTTMock(enketo_mock):
settings.CSV_ROW_IMPORT_ASYNC_THRESHOLD = 5
settings.CSV_FILESIZE_IMPORT_ASYNC_THRESHOLD = 20
mock_submit_csv_async.delay.return_value = None
self._publish_xls_form_to_project()
view = XFormViewSet.as_view({'post': 'csv_import'})
Expand All @@ -1917,7 +1917,7 @@ def test_raise_error_when_task_is_none(self, mock_submit_csv_async):
@patch('onadata.apps.api.viewsets.xform_viewset.submit_csv_async')
def test_import_csv_asynchronously(self, mock_submit_csv_async):
with HTTMock(enketo_mock):
settings.CSV_ROW_IMPORT_ASYNC_THRESHOLD = 5
settings.CSV_FILESIZE_IMPORT_ASYNC_THRESHOLD = 20
self._publish_xls_form_to_project()
view = XFormViewSet.as_view({'post': 'csv_import'})
csv_import = fixtures_path('good.csv')
Expand Down
4 changes: 2 additions & 2 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ def csv_import(self, request, *args, **kwargs):
if csv_file is None:
resp.update({u'error': u'csv_file field empty'})
else:
num_rows = sum(1 for row in csv_file) - 1
if num_rows < settings.CSV_ROW_IMPORT_ASYNC_THRESHOLD:
size_threshold = settings.CSV_FILESIZE_IMPORT_ASYNC_THRESHOLD
if csv_file.size < size_threshold:
resp.update(submit_csv(request.user.username,
self.object, csv_file))
else:
Expand Down
2 changes: 1 addition & 1 deletion onadata/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def configure_logging(logger, **kwargs):
CELERY_RESULT_BACKEND = "amqp" # telling Celery to report results to RabbitMQ
CELERY_ALWAYS_EAGER = False
CELERY_IMPORTS = ('onadata.libs.utils.csv_import',)
CSV_ROW_IMPORT_ASYNC_THRESHOLD = 100
CSV_FILESIZE_IMPORT_ASYNC_THRESHOLD = 100000 # Bytes
GOOGLE_SHEET_UPLOAD_BATCH = 1000

# duration to keep zip exports before deletion (in seconds)
Expand Down