Skip to content

Commit

Permalink
Make sure there is an event for any query execution (#4051)
Browse files Browse the repository at this point in the history
* move event recording for query executions inside run_query

* include indication of cache hit or miss inside execute_query events
  • Loading branch information
Omer Lachish authored and arikfr committed Aug 9, 2019
1 parent 77625b2 commit cf7aef1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions redash/handlers/query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flask_login import current_user
from flask_restful import abort
from redash import models, settings
from redash.handlers.base import BaseResource, get_object_or_404
from redash.handlers.base import BaseResource, get_object_or_404, record_event
from redash.permissions import (has_access, not_view_only, require_access,
require_permission, view_only)
from redash.tasks import QueryTask
Expand Down Expand Up @@ -49,6 +49,16 @@ def run_query(query, parameters, data_source, query_id, max_age=0):
else:
query_result = models.QueryResult.get_latest(data_source, query.text, max_age)

record_event(current_user.org, current_user, {
'action': 'execute_query',
'cache': 'hit' if query_result else 'miss',
'object_id': data_source.id,
'object_type': 'data_source',
'query': query.text,
'query_id': query_id,
'parameters': parameters
})

if query_result:
return {'query_result': serialize_query_result(query_result, current_user.is_api_user())}
else:
Expand Down Expand Up @@ -105,14 +115,6 @@ def post(self):
if not has_access(data_source, self.current_user, not_view_only):
return error_messages['no_permission']

self.record_event({
'action': 'execute_query',
'object_id': data_source.id,
'object_type': 'data_source',
'query': query,
'query_id': query_id,
'parameters': parameters
})
return run_query(parameterized_query, parameters, data_source, query_id, max_age)


Expand Down

0 comments on commit cf7aef1

Please sign in to comment.