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:
parent
4515925ac2
commit
e0f0108c19
@ -253,17 +253,26 @@ export default class ClientInstanceStore implements IClientInstanceStore {
|
||||
}
|
||||
|
||||
async getDistinctApplicationsCount(daysBefore?: number): Promise<number> {
|
||||
let query = this.db.from(TABLE);
|
||||
const query = this.db
|
||||
.from((qb) =>
|
||||
qb
|
||||
.select('app_name')
|
||||
.from(TABLE)
|
||||
.modify((qb) => {
|
||||
if (daysBefore) {
|
||||
query = query.where(
|
||||
qb.where(
|
||||
'last_seen',
|
||||
'>',
|
||||
subDays(new Date(), daysBefore),
|
||||
);
|
||||
}
|
||||
return query
|
||||
.countDistinct('app_name')
|
||||
.then((res) => Number(res[0].count));
|
||||
})
|
||||
.groupBy('app_name')
|
||||
.as('subquery'),
|
||||
)
|
||||
.count('* as count');
|
||||
|
||||
return query.then((res) => Number(res[0].count));
|
||||
}
|
||||
|
||||
async deleteForApplication(appName: string): Promise<void> {
|
||||
|
Loading…
Reference in New Issue
Block a user