1
0
mirror of https://github.com/immich-app/immich.git synced 2025-01-20 16:42:43 +02:00

refactor: activity queries ()

This commit is contained in:
Daniel Dietzler 2025-01-10 00:14:36 +01:00 committed by GitHub
parent 1fb2b3f899
commit 7d50d3032b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 4 deletions

@ -31,11 +31,11 @@ select
count(*) as "count"
from
"activity"
left join "users" on "users"."id" = "activity"."userId"
inner join "users" on "users"."id" = "activity"."userId"
and "users"."deletedAt" is null
left join "assets" on "assets"."id" = "activity"."assetId"
where
"activity"."assetId" = $1
and "activity"."albumId" = $2
and "activity"."isLiked" = $3
and "users"."deletedAt" is null
and "assets"."deletedAt" is null

@ -60,12 +60,11 @@ export class ActivityRepository implements IActivityRepository {
const { count } = await this.db
.selectFrom('activity')
.select((eb) => eb.fn.countAll().as('count'))
.leftJoin('users', 'users.id', 'activity.userId')
.innerJoin('users', (join) => join.onRef('users.id', '=', 'activity.userId').on('users.deletedAt', 'is', null))
.leftJoin('assets', 'assets.id', 'activity.assetId')
.$if(!!assetId, (qb) => qb.where('activity.assetId', '=', assetId!))
.where('activity.albumId', '=', albumId)
.where('activity.isLiked', '=', false)
.where('users.deletedAt', 'is', null)
.where('assets.deletedAt', 'is', null)
.executeTakeFirstOrThrow();