1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-10 17:53:36 +02:00

feat: SQL performance optimization to count instances (#9369)

This commit is contained in:
Jaanus Sellin 2025-02-27 09:11:00 +02:00 committed by GitHub
parent 4515925ac2
commit e0f0108c19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -253,17 +253,26 @@ export default class ClientInstanceStore implements IClientInstanceStore {
} }
async getDistinctApplicationsCount(daysBefore?: number): Promise<number> { async getDistinctApplicationsCount(daysBefore?: number): Promise<number> {
let query = this.db.from(TABLE); const query = this.db
if (daysBefore) { .from((qb) =>
query = query.where( qb
'last_seen', .select('app_name')
'>', .from(TABLE)
subDays(new Date(), daysBefore), .modify((qb) => {
); if (daysBefore) {
} qb.where(
return query 'last_seen',
.countDistinct('app_name') '>',
.then((res) => Number(res[0].count)); subDays(new Date(), daysBefore),
);
}
})
.groupBy('app_name')
.as('subquery'),
)
.count('* as count');
return query.then((res) => Number(res[0].count));
} }
async deleteForApplication(appName: string): Promise<void> { async deleteForApplication(appName: string): Promise<void> {