Skip to content
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
32 changes: 28 additions & 4 deletions qiita_db/handlers/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------

from tornado import gen
from tornado.web import HTTPError
from json import dumps

import qiita_db as qdb
from .oauth2 import OauthBaseHandler, authenticate_oauth
Expand Down Expand Up @@ -44,7 +46,7 @@ def _get_analysis(a_id):

class APIAnalysisMetadataHandler(OauthBaseHandler):
@authenticate_oauth
def get(self, analysis_id):
async def get(self, analysis_id):
"""Retrieves the analysis metadata

Parameters
Expand All @@ -56,15 +58,37 @@ def get(self, analysis_id):
-------
dict
The contents of the analysis keyed by sample id

Notes
-----
This response needed to be broken in chunks because we were hitting
the max size of a respose: 2G; based on: https://bit.ly/3CPvyjd
"""
chunk_len = 1024 * 1024 * 1 # 1 MiB

response = None
with qdb.sql_connection.TRN:
a = _get_analysis(analysis_id)
mf_fp = qdb.util.get_filepath_information(
a.mapping_file)['fullpath']
response = None
if mf_fp is not None:
df = qdb.metadata_template.util.load_template_to_dataframe(
mf_fp, index='#SampleID')
response = df.to_dict(orient='index')
response = dumps(df.to_dict(orient='index'))
Copy link
Contributor

Choose a reason for hiding this comment

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

i think all of this makes sense, but I think it should be possible to do this outside of the TRN context, and close the transaction?


if response is not None:
crange = range(chunk_len, len(response)+chunk_len, chunk_len)
for i, (win) in enumerate(crange):
# sending the chunk and flushing
chunk = response[i*chunk_len:win]
self.write(chunk)
await self.flush()

# cleaning chuck and pause the coroutine so other handlers
# can run, note that this is required/important based on the
# original implementation in https://bit.ly/3CPvyjd
del chunk
await gen.sleep(0.000000001) # 1 nanosecond

self.write(response)
else:
self.write(None)
4 changes: 2 additions & 2 deletions scripts/qiita-test-install
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ class QiitaConfig(TestCase):
string_acceptable_version))

def test_redbiom_version(self):
acceptable_version = (0, 3, 5)
acceptable_version = (0, 3, 8)
string_acceptable_version = '.'.join(map(str, acceptable_version))
version = tuple(map(int, redbiom_lib_version.split('.')))

self.assertTrue(acceptable_version == version,
self.assertTrue(acceptable_version >= version,
'Unsupported redbiom version. You have %s but the '
'minimum required version is %s'
% ('.'.join(map(str, version)),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
install_requires=['psycopg2', 'click', 'bcrypt', 'pandas',
'biom-format', 'tornado<6.0', 'toredis', 'redis',
'scp', 'pyparsing', 'h5py', 'natsort', 'nose', 'pep8',
'networkx', 'humanize', 'scikit-bio', 'wtforms',
'networkx', 'humanize', 'scikit-bio', 'wtforms<3.0.0',
'openpyxl', 'sphinx-bootstrap-theme', 'Sphinx', 'nltk',
'gitpython', 'redbiom', 'pyzmq', 'sphinx_rtd_theme',
'paramiko', 'seaborn', 'matplotlib', 'scipy', 'nose',
Expand Down