Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
use the textless endpoint (/api/queries/:id/results) for pristine
Browse files Browse the repository at this point in the history
queriest
  • Loading branch information
Omer Lachish committed Jan 30, 2019
1 parent 0b9f575 commit cd2cee7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
6 changes: 3 additions & 3 deletions client/app/pages/queries/view.js
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);
$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
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
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);
}

return this.queryResult;
Expand Down

0 comments on commit cd2cee7

Please sign in to comment.