Skip to content

Commit

Permalink
Use textless endpoint for pristine queries (#3367)
Browse files Browse the repository at this point in the history
* use the textless endpoint (/api/queries/:id/results) for pristine
queriest

* Revert "use the textless endpoint (/api/queries/:id/results) for pristine"

This reverts commit cd2cee7.

* move execution preparation to a different function, which will be soon
reused

* go to textless /api/queries/:id/results by default

* let the query view decide if text or textless endpoint is needed

* lint
  • Loading branch information
Omer Lachish authored Feb 5, 2019
1 parent 3df3724 commit 8f0cffe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
7 changes: 6 additions & 1 deletion client/app/pages/queries/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ function QueryViewCtrl(
}

$scope.showLog = false;
$scope.queryResult = $scope.query.getQueryResult(maxAge, selectedQueryText);
if ($scope.isDirty) {
$scope.queryResult = $scope.query.getQueryResultByText(maxAge, selectedQueryText);
} else {
$scope.queryResult = $scope.query.getQueryResult(maxAge);
}
}


function getDataSourceId() {
// Try to get the query's data source id
let dataSourceId = $scope.query.data_source_id;
Expand Down
24 changes: 24 additions & 0 deletions client/app/services/query-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,30 @@ function QueryResultService($resource, $timeout, $q, QueryResultError) {
return `${queryName.replace(/ /g, '_') + moment(this.getUpdatedAt()).format('_YYYY_MM_DD')}.${fileType}`;
}

static getByQueryId(id, parameters, maxAge) {
const queryResult = new QueryResult();

$resource('api/queries/:id/results', { id: '@id' }, { post: { method: 'POST' } }).post(
{
id,
parameters,
max_age: maxAge,
},
(response) => {
queryResult.update(response);

if ('job' in response) {
queryResult.refreshStatus(id);
}
},
(error) => {
handleErrorResponse(queryResult, error);
},
);

return queryResult;
}

static get(dataSourceId, query, parameters, maxAge, queryId) {
const queryResult = new QueryResult();

Expand Down
17 changes: 14 additions & 3 deletions client/app/services/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,11 @@ function QueryResource(
return this.getParameters().isRequired();
};

QueryService.prototype.getQueryResult = function getQueryResult(maxAge, selectedQueryText) {
QueryService.prototype.prepareQueryResultExecution = function prepareQueryResultExecution(execute, maxAge) {
if (!this.query) {
return new QueryResultError("Can't execute empty query.");
}

const queryText = selectedQueryText || this.query;
const parameters = this.getParameters();
const missingParams = parameters.getMissing();

Expand Down Expand Up @@ -476,14 +475,26 @@ function QueryResource(
this.queryResult = QueryResult.getById(this.latest_query_data_id);
}
} else if (this.data_source_id) {
this.queryResult = QueryResult.get(this.data_source_id, queryText, parameters.getValues(), maxAge, this.id);
this.queryResult = execute();
} else {
return new QueryResultError('Please select data source to run this query.');
}

return this.queryResult;
};

QueryService.prototype.getQueryResult = function getQueryResult(maxAge) {
const execute = () => QueryResult.getByQueryId(this.id, this.getParameters().getValues());
return this.prepareQueryResultExecution(execute, maxAge);
};

QueryService.prototype.getQueryResultByText = function getQueryResultByText(maxAge, selectedQueryText) {
const queryText = selectedQueryText || this.query;
const parameters = this.getParameters().getValues();
const execute = () => QueryResult.get(this.data_source_id, queryText, parameters, maxAge, this.id);
return this.prepareQueryResultExecution(execute, maxAge);
};

QueryService.prototype.getUrl = function getUrl(source, hash) {
let url = `queries/${this.id}`;

Expand Down

0 comments on commit 8f0cffe

Please sign in to comment.