1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-09 21:36:46 +01:00
immich/server/src/domain/repositories
Michael Manganiello 6d1b325b34
chore(server): Check album permissions in bulk (#5290)
* chore(server): Check album permissions in bulk

Modify Access repository, to evaluate `album` permissions in bulk.
Queries have been validated to match what they currently generate for
single ids.

Queries:

* Owner access:

```sql
-- Before
SELECT 1 AS "row_exists" FROM (SELECT 1 AS dummy_column) "dummy_table" WHERE EXISTS (
  SELECT 1
  FROM "albums" "AlbumEntity"
  WHERE
    "AlbumEntity"."id" = $1
    AND "AlbumEntity"."ownerId" = $2
    AND "AlbumEntity"."deletedAt" IS NULL
)
LIMIT 1

-- After
SELECT
  "AlbumEntity"."id" AS "AlbumEntity_id"
FROM "albums" "AlbumEntity"
WHERE
  "AlbumEntity"."id" IN ($1, $2)
  AND "AlbumEntity"."ownerId" = $3
  AND "AlbumEntity"."deletedAt" IS NULL
```

* Shared link access:

```sql
-- Before
SELECT 1 AS "row_exists" FROM (SELECT 1 AS dummy_column) "dummy_table" WHERE EXISTS (
  SELECT 1
  FROM "shared_links" "SharedLinkEntity"
  WHERE
    "SharedLinkEntity"."id" = $1
    AND "SharedLinkEntity"."albumId" = $2
)
LIMIT 1

-- After
SELECT
  "SharedLinkEntity"."albumId" AS "SharedLinkEntity_albumId",
  "SharedLinkEntity"."id" AS "SharedLinkEntity_id"
FROM "shared_links" "SharedLinkEntity"
WHERE
  "SharedLinkEntity"."id" = $1
  AND "SharedLinkEntity"."albumId" IN ($2, $3)
```

* Shared album access:

```sql
-- Before
SELECT 1 AS "row_exists" FROM (SELECT 1 AS dummy_column) "dummy_table" WHERE EXISTS (
  SELECT 1
  FROM "albums" "AlbumEntity"
    LEFT JOIN "albums_shared_users_users" "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"
      ON "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."albumsId"="AlbumEntity"."id"
    LEFT JOIN "users" "AlbumEntity__AlbumEntity_sharedUsers"
      ON "AlbumEntity__AlbumEntity_sharedUsers"."id"="AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."usersId"
      AND "AlbumEntity__AlbumEntity_sharedUsers"."deletedAt" IS NULL
  WHERE
    "AlbumEntity"."id" = $1
    AND "AlbumEntity__AlbumEntity_sharedUsers"."id" = $2
    AND "AlbumEntity"."deletedAt" IS NULL
)
LIMIT 1

-- After
SELECT
  "AlbumEntity"."id" AS "AlbumEntity_id"
FROM "albums" "AlbumEntity"
  LEFT JOIN "albums_shared_users_users" "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"
    ON "AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."albumsId"="AlbumEntity"."id"
  LEFT JOIN "users" "AlbumEntity__AlbumEntity_sharedUsers"
    ON "AlbumEntity__AlbumEntity_sharedUsers"."id"="AlbumEntity_AlbumEntity__AlbumEntity_sharedUsers"."usersId"
    AND "AlbumEntity__AlbumEntity_sharedUsers"."deletedAt" IS NULL
WHERE
  "AlbumEntity"."id" IN ($1, $2)
  AND "AlbumEntity__AlbumEntity_sharedUsers"."id" = $3
  AND "AlbumEntity"."deletedAt" IS NULL
```

* chore(server): Add set utils, avoid double queries for same ids

* chore(server): Review feedback
2023-11-25 17:56:23 -05:00
..
access.repository.ts chore(server): Check album permissions in bulk (#5290) 2023-11-25 17:56:23 -05:00
activity.repository.ts feat(web,server): activity (#4682) 2023-10-31 22:13:34 -05:00
album.repository.ts fix(server): album perf query (#5232) 2023-11-21 10:07:49 -06:00
api-key.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
asset.repository.ts refactor: deprecate getUserAssetsByDeviceId (#5273) 2023-11-25 15:46:20 +00:00
audit.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
communication.repository.ts refactor(server, web)!: store latest immich version available on the server (#3565) 2023-10-24 11:05:42 -04:00
crypto.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
index.ts feat: postgres reverse geocoding (#5301) 2023-11-25 18:53:30 +00:00
job.repository.ts feat(server): custom library scanning interval (#4390) 2023-10-31 15:19:12 -05:00
library.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
machine-learning.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
media.repository.ts feat(server): hardware video acceleration for Rockchip SOCs via RKMPP (#4645) 2023-10-30 09:39:37 -05:00
metadata.repository.ts feat: postgres reverse geocoding (#5301) 2023-11-25 18:53:30 +00:00
move.repository.ts feat(server): harden move file (#4361) 2023-10-10 21:14:44 -05:00
partner.repository.ts feat(web): show partners assets on the main timeline (#4933) 2023-11-11 21:06:19 +00:00
person.repository.ts fix: suggest people (#4566) 2023-10-24 15:53:49 +00:00
search.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
server-info.repository.ts refactor(server, web)!: store latest immich version available on the server (#3565) 2023-10-24 11:05:42 -04:00
shared-link.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
smart-info.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
storage.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
system-config.repository.ts feat: Maplibre (#4294) 2023-11-09 10:10:56 -06:00
system-metadata.repository.ts feat: postgres reverse geocoding (#5301) 2023-11-25 18:53:30 +00:00
tag.repository.ts refactor: domain repositories (#4403) 2023-10-09 14:25:03 +00:00
user-token.repository.ts refactor(server): auth delete device (#4720) 2023-10-30 11:48:38 -04:00
user.repository.ts fix: replace first and last name with single field (#4915) 2023-11-11 19:03:32 -06:00