forked from immich-app/immich
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate activity repo to kysely (immich-app#15203)
Co-authored-by: Jason Rasmussen <[email protected]>
- Loading branch information
1 parent
0035b15
commit 966c41e
Showing
4 changed files
with
95 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { Insertable } from 'kysely'; | ||
import { Activity } from 'src/db'; | ||
import { ActivityEntity } from 'src/entities/activity.entity'; | ||
import { ActivitySearch } from 'src/repositories/activity.repository'; | ||
|
||
export const IActivityRepository = 'IActivityRepository'; | ||
|
||
export interface IActivityRepository { | ||
search(options: ActivitySearch): Promise<ActivityEntity[]>; | ||
create(activity: Partial<ActivityEntity>): Promise<ActivityEntity>; | ||
create(activity: Insertable<Activity>): Promise<ActivityEntity>; | ||
delete(id: string): Promise<void>; | ||
getStatistics(assetId: string | undefined, albumId: string): Promise<number>; | ||
getStatistics(options: { albumId: string; assetId?: string }): Promise<number>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,41 @@ | ||
-- NOTE: This file is auto generated by ./sql-generator | ||
|
||
-- ActivityRepository.search | ||
SELECT | ||
"ActivityEntity"."id" AS "ActivityEntity_id", | ||
"ActivityEntity"."createdAt" AS "ActivityEntity_createdAt", | ||
"ActivityEntity"."updatedAt" AS "ActivityEntity_updatedAt", | ||
"ActivityEntity"."albumId" AS "ActivityEntity_albumId", | ||
"ActivityEntity"."userId" AS "ActivityEntity_userId", | ||
"ActivityEntity"."assetId" AS "ActivityEntity_assetId", | ||
"ActivityEntity"."comment" AS "ActivityEntity_comment", | ||
"ActivityEntity"."isLiked" AS "ActivityEntity_isLiked", | ||
"ActivityEntity__ActivityEntity_user"."id" AS "ActivityEntity__ActivityEntity_user_id", | ||
"ActivityEntity__ActivityEntity_user"."name" AS "ActivityEntity__ActivityEntity_user_name", | ||
"ActivityEntity__ActivityEntity_user"."isAdmin" AS "ActivityEntity__ActivityEntity_user_isAdmin", | ||
"ActivityEntity__ActivityEntity_user"."email" AS "ActivityEntity__ActivityEntity_user_email", | ||
"ActivityEntity__ActivityEntity_user"."storageLabel" AS "ActivityEntity__ActivityEntity_user_storageLabel", | ||
"ActivityEntity__ActivityEntity_user"."oauthId" AS "ActivityEntity__ActivityEntity_user_oauthId", | ||
"ActivityEntity__ActivityEntity_user"."profileImagePath" AS "ActivityEntity__ActivityEntity_user_profileImagePath", | ||
"ActivityEntity__ActivityEntity_user"."shouldChangePassword" AS "ActivityEntity__ActivityEntity_user_shouldChangePassword", | ||
"ActivityEntity__ActivityEntity_user"."createdAt" AS "ActivityEntity__ActivityEntity_user_createdAt", | ||
"ActivityEntity__ActivityEntity_user"."deletedAt" AS "ActivityEntity__ActivityEntity_user_deletedAt", | ||
"ActivityEntity__ActivityEntity_user"."status" AS "ActivityEntity__ActivityEntity_user_status", | ||
"ActivityEntity__ActivityEntity_user"."updatedAt" AS "ActivityEntity__ActivityEntity_user_updatedAt", | ||
"ActivityEntity__ActivityEntity_user"."quotaSizeInBytes" AS "ActivityEntity__ActivityEntity_user_quotaSizeInBytes", | ||
"ActivityEntity__ActivityEntity_user"."quotaUsageInBytes" AS "ActivityEntity__ActivityEntity_user_quotaUsageInBytes", | ||
"ActivityEntity__ActivityEntity_user"."profileChangedAt" AS "ActivityEntity__ActivityEntity_user_profileChangedAt" | ||
FROM | ||
"activity" "ActivityEntity" | ||
LEFT JOIN "users" "ActivityEntity__ActivityEntity_user" ON "ActivityEntity__ActivityEntity_user"."id" = "ActivityEntity"."userId" | ||
AND ( | ||
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL | ||
) | ||
LEFT JOIN "assets" "ActivityEntity__ActivityEntity_asset" ON "ActivityEntity__ActivityEntity_asset"."id" = "ActivityEntity"."assetId" | ||
AND ( | ||
"ActivityEntity__ActivityEntity_asset"."deletedAt" IS NULL | ||
) | ||
WHERE | ||
select | ||
"activity".*, | ||
( | ||
("ActivityEntity"."albumId" = $1) | ||
AND ( | ||
select | ||
to_json(obj) | ||
from | ||
( | ||
( | ||
"ActivityEntity__ActivityEntity_asset"."deletedAt" IS NULL | ||
) | ||
) | ||
) | ||
AND ( | ||
( | ||
( | ||
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL | ||
) | ||
) | ||
) | ||
) | ||
ORDER BY | ||
"ActivityEntity"."createdAt" ASC | ||
select | ||
* | ||
from | ||
"users" | ||
where | ||
"users"."id" = "activity"."userId" | ||
and "users"."deletedAt" is null | ||
) as obj | ||
) as "user" | ||
from | ||
"activity" | ||
left join "assets" on "assets"."id" = "activity"."assetId" | ||
and "assets"."deletedAt" is null | ||
where | ||
"activity"."albumId" = $1 | ||
order by | ||
"activity"."createdAt" asc | ||
|
||
-- ActivityRepository.getStatistics | ||
SELECT | ||
COUNT(DISTINCT ("ActivityEntity"."id")) AS "cnt" | ||
FROM | ||
"activity" "ActivityEntity" | ||
LEFT JOIN "users" "ActivityEntity__ActivityEntity_user" ON "ActivityEntity__ActivityEntity_user"."id" = "ActivityEntity"."userId" | ||
LEFT JOIN "assets" "ActivityEntity__ActivityEntity_asset" ON "ActivityEntity__ActivityEntity_asset"."id" = "ActivityEntity"."assetId" | ||
WHERE | ||
( | ||
("ActivityEntity"."assetId" = $1) | ||
AND ("ActivityEntity"."albumId" = $2) | ||
AND ("ActivityEntity"."isLiked" = $3) | ||
AND ( | ||
( | ||
( | ||
"ActivityEntity__ActivityEntity_asset"."deletedAt" IS NULL | ||
) | ||
) | ||
) | ||
AND ( | ||
( | ||
( | ||
"ActivityEntity__ActivityEntity_user"."deletedAt" IS NULL | ||
) | ||
) | ||
) | ||
) | ||
select | ||
count(*) as "count" | ||
from | ||
"activity" | ||
left join "users" on "users"."id" = "activity"."userId" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters