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> {
|
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> {
|
||||||
|
Loading…
Reference in New Issue
Block a user