Build aggregation query with string templates avoiding to join all inner templates

This commit is contained in:
Daniel García Aubert
2017-09-14 12:01:41 +02:00
parent a434015d5b
commit 3682740f08

View File

@@ -240,50 +240,33 @@ Aggregation.prototype.sql = function(psql, override, callback) {
return null;
}
var _query = this.query;
var aggregationSql;
if (!!override.ownFilter) {
aggregationSql = [
categoriesCTESqlTpl({
query: _query,
column: this.column,
var aggregationSql = `
${categoriesCTESqlTpl({
query: this.query,
column: this.column,
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn,
isFloatColumn: this._isFloatColumn
})}
${!!override.ownFilter ?
`${aggregationQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: this.query,
_column: this.column,
_aggregation: aggregationFnQueryTpl({
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn,
isFloatColumn: this._isFloatColumn
aggregationColumn: this.aggregationColumn || 1
}),
aggregationQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: _query,
_column: this.column,
_aggregation: aggregationFnQueryTpl({
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn || 1
}),
_limit: CATEGORIES_LIMIT
})
].join('\n');
} else {
aggregationSql = [
categoriesCTESqlTpl({
query: _query,
column: this.column,
aggregation: this.aggregation,
aggregationColumn: this.aggregationColumn,
isFloatColumn: this._isFloatColumn
}),
rankedAggregationQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: _query,
_column: this.column,
_aggregationFn: this.aggregation !== 'count' ? this.aggregation : 'sum',
_limit: CATEGORIES_LIMIT
})
].join('\n');
}
_limit: CATEGORIES_LIMIT
})}` :
`${rankedAggregationQueryTpl({
_isFloatColumn: this._isFloatColumn,
_query: this.query,
_column: this.column,
_aggregationFn: this.aggregation !== 'count' ? this.aggregation : 'sum',
_limit: CATEGORIES_LIMIT
})}`}
`;
debug(aggregationSql);