|
@@ -303,6 +303,21 @@ def top_columns(request):
|
|
|
return JsonResponse(response)
|
|
return JsonResponse(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _convert_queries(queries_data):
|
|
|
|
|
+ queries = []
|
|
|
|
|
+
|
|
|
|
|
+ for query_data in queries_data:
|
|
|
|
|
+ try:
|
|
|
|
|
+ original_query_id = '%s:%s' % struct.unpack(b"QQ", base64.decodestring(query_data['snippets'][0]['result']['handle']['guid']))
|
|
|
|
|
+ execution_time = query_data['snippets'][0]['result']['executionTime'] * 100
|
|
|
|
|
+ statement = ' '.join([line for line in _get_statement(query_data).strip().splitlines() if not line.strip().startswith('--')])
|
|
|
|
|
+ queries.append((original_query_id, execution_time, statement, query_data['snippets'][0].get('database', 'default')))
|
|
|
|
|
+ except Exception, e:
|
|
|
|
|
+ LOG.warning('Skipping upload of %s: %s' % (query_data['uuid'], e))
|
|
|
|
|
+
|
|
|
|
|
+ return queries
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@require_POST
|
|
@require_POST
|
|
|
@error_handler
|
|
@error_handler
|
|
|
def upload_history(request):
|
|
def upload_history(request):
|
|
@@ -315,16 +330,7 @@ def upload_history(request):
|
|
|
if n:
|
|
if n:
|
|
|
history = history[:n]
|
|
history = history[:n]
|
|
|
|
|
|
|
|
- queries = []
|
|
|
|
|
- for doc in history:
|
|
|
|
|
- query_data = Notebook(document=doc).get_data()
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- original_query_id = '%s:%s' % struct.unpack(b"QQ", base64.decodestring(query_data['snippets'][0]['result']['handle']['guid']))
|
|
|
|
|
- execution_time = query_data['snippets'][0]['result']['executionTime'] * 100
|
|
|
|
|
- queries.append((original_query_id, execution_time, _get_statement(query_data), query_data['snippets'][0].get('database', 'default')))
|
|
|
|
|
- except Exception, e:
|
|
|
|
|
- LOG.warning('Skipping upload of %s: %s' % (doc, e))
|
|
|
|
|
|
|
+ queries = _convert_queries([Notebook(document=doc).get_data() for doc in history])
|
|
|
|
|
|
|
|
api = OptimizerApi()
|
|
api = OptimizerApi()
|
|
|
|
|
|