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 textless endpoint for pristine queries #3367

Merged
merged 11 commits into from
Feb 5, 2019
6 changes: 3 additions & 3 deletions client/app/pages/queries/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function QueryViewCtrl(
DataSource,
Visualization,
) {
function getQueryResult(maxAge, selectedQueryText) {
function getQueryResult(maxAge, selectedQueryText, isDirty) {
if (maxAge === undefined) {
maxAge = $location.search().maxAge;
}
Expand All @@ -36,7 +36,7 @@ function QueryViewCtrl(
}

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

function getDataSourceId() {
Expand Down Expand Up @@ -118,7 +118,7 @@ function QueryViewCtrl(
return;
}

getQueryResult(0, $scope.selectedQueryText);
getQueryResult(0, $scope.selectedQueryText, $scope.isDirty);
arikfr marked this conversation as resolved.
Show resolved Hide resolved
$scope.lockButton(true);
$scope.cancelling = false;
Events.record('execute', 'query', $scope.query.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
40 changes: 22 additions & 18 deletions client/app/services/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function QueryResource(
return this.getParameters().isRequired();
};

QueryService.prototype.getQueryResult = function getQueryResult(maxAge, selectedQueryText) {
QueryService.prototype.getQueryResult = function getQueryResult(maxAge, selectedQueryText, isDirty) {
if (!this.query) {
return new QueryResultError("Can't execute empty query.");
}
Expand All @@ -454,26 +454,30 @@ function QueryResource(
});
}

if (parameters.isRequired()) {
// Need to clear latest results, to make sure we don't use results for different params.
this.latest_query_data = null;
this.latest_query_data_id = null;
}

if (this.latest_query_data && maxAge !== 0) {
if (!this.queryResult) {
this.queryResult = new QueryResult({
query_result: this.latest_query_data,
});
if (isDirty) {
if (parameters.isRequired()) {
// Need to clear latest results, to make sure we don't use results for different params.
this.latest_query_data = null;
this.latest_query_data_id = null;
}
} else if (this.latest_query_data_id && maxAge !== 0) {
if (!this.queryResult) {
this.queryResult = QueryResult.getById(this.latest_query_data_id);

if (this.latest_query_data && maxAge !== 0) {
if (!this.queryResult) {
this.queryResult = new QueryResult({
query_result: this.latest_query_data,
});
}
} else if (this.latest_query_data_id && maxAge !== 0) {
if (!this.queryResult) {
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);
} else {
return new QueryResultError('Please select data source to run this query.');
}
} else if (this.data_source_id) {
this.queryResult = QueryResult.get(this.data_source_id, queryText, parameters.getValues(), maxAge, this.id);
} else {
return new QueryResultError('Please select data source to run this query.');
this.queryResult = QueryResult.getByQueryId(this.id, parameters.getValues(), maxAge);
arikfr marked this conversation as resolved.
Show resolved Hide resolved
}

return this.queryResult;
Expand Down