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> {
let query = this.db.from(TABLE);
if (daysBefore) {
query = query.where(
'last_seen',
'>',
subDays(new Date(), daysBefore),
);
}
return query
.countDistinct('app_name')
.then((res) => Number(res[0].count));
const query = this.db
.from((qb) =>
qb
.select('app_name')
.from(TABLE)
.modify((qb) => {
if (daysBefore) {
qb.where(
'last_seen',
'>',
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> {