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
|
||||
}
|
||||
} else {
|
||||
if (args[0].query) {
|
||||
console.log('FAILED QUERY:');
|
||||
console.log(args[0].query);
|
||||
}
|
||||
|
||||
// Handle other errors or rethrow them
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ export function getChartSql({
|
||||
startDate,
|
||||
endDate,
|
||||
projectId,
|
||||
chartType,
|
||||
limit,
|
||||
}: IGetChartDataInput) {
|
||||
const { sb, join, getWhere, getFrom, getSelect, getOrderBy, getGroupBy } =
|
||||
createSqlBuilder();
|
||||
@@ -59,6 +61,17 @@ export function getChartSql({
|
||||
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) => {
|
||||
const key = `label_${index}`;
|
||||
const value = breakdown.name.startsWith('properties.')
|
||||
|
||||
Reference in New Issue
Block a user