Skip to content

High performance self-hosted photo and video management solution.

fix: album comment count including trashed assets (#19117)

Zack Pollard08e2b22db860
diff --git a/server/src/queries/activity.repository.sql b/server/src/queries/activity.repository.sql
index 59eaeb835a..01c4f901cb 100644
--- a/server/src/queries/activity.repository.sql
+++ b/server/src/queries/activity.repository.sql
@@ -75,8 +75,13 @@ from
inner join "users" on "users"."id" = "activity"."userId"
and "users"."deletedAt" is null
left join "assets" on "assets"."id" = "activity"."assetId"
- and "assets"."deletedAt" is null
- and "assets"."visibility" != 'locked'
where
"activity"."assetId" = $3
and "activity"."albumId" = $4
+ and (
+ (
+ "assets"."deletedAt" is null
+ and "assets"."visibility" != 'locked'
+ )
+ or "assets"."id" is null
+ )
diff --git a/server/src/repositories/activity.repository.ts b/server/src/repositories/activity.repository.ts
index 925a74ff2a..ecde95cf78 100644
--- a/server/src/repositories/activity.repository.ts
+++ b/server/src/repositories/activity.repository.ts
@@ -82,14 +82,15 @@ export class ActivityRepository {
eb.fn.countAll<number>().filterWhere('activity.isLiked', '=', true).as('likes'),
])
.innerJoin('users', (join) => join.onRef('users.id', '=', 'activity.userId').on('users.deletedAt', 'is', null))
- .leftJoin('assets', (join) =>
- join
- .onRef('assets.id', '=', 'activity.assetId')
- .on('assets.deletedAt', 'is', null)
- .on('assets.visibility', '!=', sql.lit(AssetVisibility.LOCKED)),
- )
+ .leftJoin('assets', 'assets.id', 'activity.assetId')
.$if(!!assetId, (qb) => qb.where('activity.assetId', '=', assetId!))
.where('activity.albumId', '=', albumId)
+ .where(({ or, and, eb }) =>
+ or([
+ and([eb('assets.deletedAt', 'is', null), eb('assets.visibility', '!=', sql.lit(AssetVisibility.LOCKED))]),
+ eb('assets.id', 'is', null),
+ ]),
+ )
.executeTakeFirstOrThrow();
return result;