improve queries with limit
This commit is contained in:
@@ -56,6 +56,11 @@ export const ch = new Proxy(originalCh, {
|
|||||||
throw retryError; // Rethrow or handle as needed
|
throw retryError; // Rethrow or handle as needed
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (args[0].query) {
|
||||||
|
console.log('FAILED QUERY:');
|
||||||
|
console.log(args[0].query);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle other errors or rethrow them
|
// Handle other errors or rethrow them
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export function getChartSql({
|
|||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
projectId,
|
projectId,
|
||||||
|
chartType,
|
||||||
|
limit,
|
||||||
}: IGetChartDataInput) {
|
}: IGetChartDataInput) {
|
||||||
const { sb, join, getWhere, getFrom, getSelect, getOrderBy, getGroupBy } =
|
const { sb, join, getWhere, getFrom, getSelect, getOrderBy, getGroupBy } =
|
||||||
createSqlBuilder();
|
createSqlBuilder();
|
||||||
@@ -59,6 +61,17 @@ export function getChartSql({
|
|||||||
sb.where.endDate = `created_at <= '${formatClickhouseDate(endDate)}'`;
|
sb.where.endDate = `created_at <= '${formatClickhouseDate(endDate)}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (breakdowns.length > 0 && limit) {
|
||||||
|
sb.where.bar = `(${breakdowns.map((b) => b.name).join(',')}) IN (
|
||||||
|
SELECT ${breakdowns.map((b) => b.name).join(',')}
|
||||||
|
FROM ${TABLE_NAMES.events}
|
||||||
|
${getWhere()}
|
||||||
|
GROUP BY ${breakdowns.map((b) => b.name).join(',')}
|
||||||
|
ORDER BY count(*) DESC
|
||||||
|
LIMIT ${limit}
|
||||||
|
)`;
|
||||||
|
}
|
||||||
|
|
||||||
breakdowns.forEach((breakdown, index) => {
|
breakdowns.forEach((breakdown, index) => {
|
||||||
const key = `label_${index}`;
|
const key = `label_${index}`;
|
||||||
const value = breakdown.name.startsWith('properties.')
|
const value = breakdown.name.startsWith('properties.')
|
||||||
|
|||||||
Reference in New Issue
Block a user