mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor: rewrite countAll SQL to use GROUP BY count
Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
@@ -39,28 +39,16 @@ export class IntegrityRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [] })
|
@GenerateSql({ params: [] })
|
||||||
getIntegrityReportSummary() {
|
async getIntegrityReportSummary() {
|
||||||
return this.db
|
const counts = await this.db
|
||||||
.selectFrom('integrity_report')
|
.selectFrom('integrity_report')
|
||||||
.select((eb) =>
|
.select(['type', this.db.fn.countAll<number>().as('count')])
|
||||||
eb.fn
|
.groupBy('type')
|
||||||
.countAll<number>()
|
.execute();
|
||||||
.filterWhere('type', '=', IntegrityReportType.ChecksumFail)
|
|
||||||
.as(IntegrityReportType.ChecksumFail),
|
return Object.fromEntries(
|
||||||
)
|
Object.values(IntegrityReportType).map((type) => [type, counts.find((count) => count.type === type)?.count || 0]),
|
||||||
.select((eb) =>
|
) as Record<IntegrityReportType, number>;
|
||||||
eb.fn
|
|
||||||
.countAll<number>()
|
|
||||||
.filterWhere('type', '=', IntegrityReportType.MissingFile)
|
|
||||||
.as(IntegrityReportType.MissingFile),
|
|
||||||
)
|
|
||||||
.select((eb) =>
|
|
||||||
eb.fn
|
|
||||||
.countAll<number>()
|
|
||||||
.filterWhere('type', '=', IntegrityReportType.UntrackedFile)
|
|
||||||
.as(IntegrityReportType.UntrackedFile),
|
|
||||||
)
|
|
||||||
.executeTakeFirstOrThrow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [{ cursor: DummyValue.NUMBER, limit: 100 }, DummyValue.STRING] })
|
@GenerateSql({ params: [{ cursor: DummyValue.NUMBER, limit: 100 }, DummyValue.STRING] })
|
||||||
|
|||||||
Reference in New Issue
Block a user