Build aggregation query with string templates avoiding to join all inner templates
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user