Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Jan 28, 2025
1 parent 41800d6 commit e213a74
Show file tree
Hide file tree
Showing 24 changed files with 207 additions and 16 deletions.
1 change: 1 addition & 0 deletions e2e/src/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ describe('/libraries', () => {
expect(status).toBe(204);

await utils.waitForQueueFinish(admin.accessToken, 'library');
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');

const { assets } = await utils.searchAssets(admin.accessToken, {
originalPath: `${testAssetDirInternal}/temp/directoryA/assetA.png`,
Expand Down
8 changes: 8 additions & 0 deletions server/src/dtos/asset-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ const hexOrBufferToBase64 = (encoded: string | Buffer) => {
export function mapAsset(entity: AssetEntity, options: AssetMapOptions = {}): AssetResponseDto {
const { stripMetadata = false, withStack = false } = options;

if (!entity.localDateTime) {
throw new Error('Asset localDateTime is missing');
} else if (!entity.fileCreatedAt) {
throw new Error('Asset fileCreatedAt is missing');
} else if (!entity.fileModifiedAt) {
throw new Error('Asset fileModifiedAt is missing');
}

if (stripMetadata) {
const sanitizedAssetResponse: SanitizedAssetResponseDto = {
id: entity.id,
Expand Down
5 changes: 4 additions & 1 deletion server/src/entities/asset.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,8 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
)
.$if(!!options.withExif, withExifInner)
.$if(!!(options.withFaces || options.withPeople || options.personIds), (qb) => qb.select(withFacesAndPeople))
.$if(!options.withDeleted, (qb) => qb.where('assets.deletedAt', 'is', null));
.$if(!options.withDeleted, (qb) => qb.where('assets.deletedAt', 'is', null))
.$if(!options.withNullFileModifiedAt, (qb) => qb.where('assets.fileModifiedAt', 'is not', null))
.$if(!options.withNullFileCreatedAt, (qb) => qb.where('assets.fileCreatedAt', 'is not', null))
.$if(!options.withNullLocalDateTime, (qb) => qb.where('assets.localDateTime', 'is not', null));
}
3 changes: 3 additions & 0 deletions server/src/interfaces/search.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export interface SearchStatusOptions {
status?: AssetStatus;
withArchived?: boolean;
withDeleted?: boolean;
withNullLocalDateTime?: boolean;
withNullFileCreatedAt?: boolean;
withNullFileModifiedAt?: boolean;
}

export interface SearchOneToOneRelationOptions {
Expand Down
12 changes: 12 additions & 0 deletions server/src/queries/access.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ from
inner join "albums_assets_assets" as "albumAssets" on "albums"."id" = "albumAssets"."albumsId"
inner join "assets" on "assets"."id" = "albumAssets"."assetsId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
left join "albums_shared_users_users" as "albumUsers" on "albumUsers"."albumsId" = "albums"."id"
left join "users" on "users"."id" = "albumUsers"."usersId"
and "users"."deletedAt" is null
Expand Down Expand Up @@ -108,6 +111,9 @@ from
and "sharedBy"."deletedAt" is null
inner join "assets" on "assets"."ownerId" = "sharedBy"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
where
"partner"."sharedWithId" = $1
and "assets"."isArchived" = $2
Expand All @@ -126,6 +132,9 @@ from
left join "shared_link__asset" on "shared_link__asset"."sharedLinksId" = "shared_links"."id"
left join "assets" on "assets"."id" = "shared_link__asset"."assetsId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
left join "albums_assets_assets" on "albums_assets_assets"."albumsId" = "albums"."id"
left join "assets" as "albumAssets" on "albumAssets"."id" = "albums_assets_assets"."assetsId"
and "albumAssets"."deletedAt" is null
Expand Down Expand Up @@ -173,6 +182,9 @@ from
"asset_faces"
left join "assets" on "assets"."id" = "asset_faces"."assetId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
where
"asset_faces"."id" in ($1)
and "assets"."ownerId" = $2
Expand Down
6 changes: 6 additions & 0 deletions server/src/queries/activity.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ from
"activity"
left join "assets" on "assets"."id" = "activity"."assetId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
where
"activity"."albumId" = $1
order by
Expand All @@ -43,3 +46,6 @@ where
and "activity"."albumId" = $2
and "activity"."isLiked" = $3
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
6 changes: 6 additions & 0 deletions server/src/queries/album.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ select
where
"albums_assets_assets"."albumsId" = "albums"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" desc
) as "asset"
Expand Down Expand Up @@ -212,6 +215,9 @@ from
where
"albums"."id" in ($1)
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
group by
"albums"."id"

Expand Down
8 changes: 6 additions & 2 deletions server/src/queries/asset.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ with
and (assets."localDateTime" at time zone 'UTC')::date = today.date
and "assets"."ownerId" = any ($3::uuid[])
and "assets"."isVisible" = $4
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."isArchived" = $5
and exists (
select
Expand All @@ -49,6 +47,9 @@ with
and "asset_files"."type" = $6
)
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
limit
$7
) as "a" on true
Expand Down Expand Up @@ -266,6 +267,7 @@ with
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
)
select
"timeBucket",
Expand Down Expand Up @@ -308,6 +310,7 @@ where
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and date_trunc($3, "localDateTime" at time zone 'UTC') at time zone 'UTC' = $4
order by
"assets"."localDateTime" desc
Expand Down Expand Up @@ -336,6 +339,7 @@ with
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
group by
"assets"."duplicateId"
),
Expand Down
6 changes: 6 additions & 0 deletions server/src/queries/memory.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ select
where
"memories_assets_assets"."memoriesId" = "memories"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
) as agg
) as "assets"
from
Expand Down Expand Up @@ -56,6 +59,9 @@ select
where
"memories_assets_assets"."memoriesId" = "memories"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
) as agg
) as "assets"
from
Expand Down
6 changes: 6 additions & 0 deletions server/src/queries/person.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ from
and "asset_faces"."personId" = $1
and "assets"."isArchived" = $2
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."livePhotoVideoId" is null

-- PersonRepository.getNumberOfPeople
Expand All @@ -183,6 +186,9 @@ from
inner join "asset_faces" on "asset_faces"."personId" = "person"."id"
inner join "assets" on "assets"."id" = "asset_faces"."assetId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."isArchived" = $2
where
"person"."ownerId" = $3
Expand Down
24 changes: 24 additions & 0 deletions server/src/queries/search.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ where
and "assets"."isFavorite" = $4
and "assets"."isArchived" = $5
and "assets"."deletedAt" is null
and "assets"."fileModifiedAt" is not null
and "assets"."fileCreatedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" desc
limit
Expand All @@ -34,6 +37,9 @@ offset
and "assets"."isFavorite" = $4
and "assets"."isArchived" = $5
and "assets"."deletedAt" is null
and "assets"."fileModifiedAt" is not null
and "assets"."fileCreatedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."id" < $6
order by
random()
Expand All @@ -54,6 +60,9 @@ union all
and "assets"."isFavorite" = $11
and "assets"."isArchived" = $12
and "assets"."deletedAt" is null
and "assets"."fileModifiedAt" is not null
and "assets"."fileCreatedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."id" > $13
order by
random()
Expand All @@ -77,6 +86,9 @@ where
and "assets"."isFavorite" = $4
and "assets"."isArchived" = $5
and "assets"."deletedAt" is null
and "assets"."fileModifiedAt" is not null
and "assets"."fileCreatedAt" is not null
and "assets"."localDateTime" is not null
order by
smart_search.embedding <=> $6
limit
Expand All @@ -98,6 +110,9 @@ with
"assets"."ownerId" = any ($2::uuid[])
and "assets"."deletedAt" is null
and "assets"."isVisible" = $3
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."type" = $4
and "assets"."id" != $5::uuid
order by
Expand Down Expand Up @@ -126,6 +141,9 @@ with
where
"assets"."ownerId" = any ($2::uuid[])
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
face_search.embedding <=> $3
limit
Expand Down Expand Up @@ -178,6 +196,9 @@ with recursive
and "assets"."isArchived" = $3
and "assets"."type" = $4
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"city"
limit
Expand All @@ -203,6 +224,9 @@ with recursive
and "assets"."isArchived" = $8
and "assets"."type" = $9
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "exif"."city" > "cte"."city"
order by
"city"
Expand Down
9 changes: 9 additions & 0 deletions server/src/queries/shared.link.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ from
where
"shared_links"."id" = "shared_link__asset"."sharedLinksId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" asc
) as "a" on true
Expand Down Expand Up @@ -65,6 +68,9 @@ from
where
"albums_assets_assets"."assetsId" = "assets"."id"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
order by
"assets"."fileCreatedAt" asc
) as "assets" on true
Expand Down Expand Up @@ -112,6 +118,9 @@ from
where
"assets"."id" = "shared_link__asset"."assetsId"
and "assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
) as "assets" on true
left join lateral (
select
Expand Down
9 changes: 9 additions & 0 deletions server/src/queries/stack.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ select
) as "exifInfo" on true
where
"assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."stackId" = "asset_stack"."id"
) as agg
) as "assets"
Expand Down Expand Up @@ -68,6 +71,9 @@ select
) as "exifInfo" on true
where
"assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."stackId" = "asset_stack"."id"
) as agg
) as "assets"
Expand Down Expand Up @@ -113,6 +119,9 @@ select
) as "exifInfo" on true
where
"assets"."deletedAt" is null
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
and "assets"."stackId" = "asset_stack"."id"
) as agg
) as "assets"
Expand Down
28 changes: 24 additions & 4 deletions server/src/repositories/access.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ class AssetAccess {
.selectFrom('albums')
.innerJoin('albums_assets_assets as albumAssets', 'albums.id', 'albumAssets.albumsId')
.innerJoin('assets', (join) =>
join.onRef('assets.id', '=', 'albumAssets.assetsId').on('assets.deletedAt', 'is', null),
join
.onRef('assets.id', '=', 'albumAssets.assetsId')
.on('assets.deletedAt', 'is', null)
.on('assets.fileCreatedAt', 'is not', null)
.on('assets.fileModifiedAt', 'is not', null)
.on('assets.localDateTime', 'is not', null),
)
.leftJoin('albums_shared_users_users as albumUsers', 'albumUsers.albumsId', 'albums.id')
.leftJoin('users', (join) => join.onRef('users.id', '=', 'albumUsers.usersId').on('users.deletedAt', 'is', null))
Expand Down Expand Up @@ -194,7 +199,12 @@ class AssetAccess {
join.onRef('sharedBy.id', '=', 'partner.sharedById').on('sharedBy.deletedAt', 'is', null),
)
.innerJoin('assets', (join) =>
join.onRef('assets.ownerId', '=', 'sharedBy.id').on('assets.deletedAt', 'is', null),
join
.onRef('assets.ownerId', '=', 'sharedBy.id')
.on('assets.deletedAt', 'is', null)
.on('assets.fileCreatedAt', 'is not', null)
.on('assets.fileModifiedAt', 'is not', null)
.on('assets.localDateTime', 'is not', null),
)
.select('assets.id')
.where('partner.sharedWithId', '=', userId)
Expand All @@ -218,7 +228,12 @@ class AssetAccess {
)
.leftJoin('shared_link__asset', 'shared_link__asset.sharedLinksId', 'shared_links.id')
.leftJoin('assets', (join) =>
join.onRef('assets.id', '=', 'shared_link__asset.assetsId').on('assets.deletedAt', 'is', null),
join
.onRef('assets.id', '=', 'shared_link__asset.assetsId')
.on('assets.deletedAt', 'is', null)
.on('assets.fileCreatedAt', 'is not', null)
.on('assets.fileModifiedAt', 'is not', null)
.on('assets.localDateTime', 'is not', null),
)
.leftJoin('albums_assets_assets', 'albums_assets_assets.albumsId', 'albums.id')
.leftJoin('assets as albumAssets', (join) =>
Expand Down Expand Up @@ -369,7 +384,12 @@ class PersonAccess {
.selectFrom('asset_faces')
.select('asset_faces.id')
.leftJoin('assets', (join) =>
join.onRef('assets.id', '=', 'asset_faces.assetId').on('assets.deletedAt', 'is', null),
join
.onRef('assets.id', '=', 'asset_faces.assetId')
.on('assets.deletedAt', 'is', null)
.on('assets.fileCreatedAt', 'is not', null)
.on('assets.fileModifiedAt', 'is not', null)
.on('assets.localDateTime', 'is not', null),
)
.where('asset_faces.id', 'in', [...assetFaceIds])
.where('assets.ownerId', '=', userId)
Expand Down
Loading

0 comments on commit e213a74

Please sign in to comment.