Skip to content

Commit

Permalink
remove externality checks
Browse files Browse the repository at this point in the history
etnoy committed Jan 28, 2025
1 parent d3f7996 commit 2504dbb
Showing 6 changed files with 22 additions and 43 deletions.
5 changes: 4 additions & 1 deletion server/src/entities/asset.entity.ts
Original file line number Diff line number Diff line change
@@ -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.withNullLocalDateTime, (qb) => qb.where('assets.localDateTime', 'is not', null))
.$if(!options.withNullFileCreatedAt, (qb) => qb.where('assets.fileCreatedAt', 'is not', null))
.$if(!options.withNullFileModifiedAt, (qb) => qb.where('assets.fileModifiedAt', '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
@@ -63,6 +63,9 @@ export interface SearchStatusOptions {
status?: AssetStatus;
withArchived?: boolean;
withDeleted?: boolean;
withNullLocalDateTime?: boolean;
withNullFileCreatedAt?: boolean;
withNullFileModifiedAt?: boolean;
}

export interface SearchOneToOneRelationOptions {
12 changes: 5 additions & 7 deletions server/src/queries/asset.repository.sql
Original file line number Diff line number Diff line change
@@ -263,9 +263,8 @@ with
from
"assets"
where
"assets"."fileCreatedAt" <= $2
and "assets"."deletedAt" is null
and "assets"."isVisible" = $3
"assets"."deletedAt" is null
and "assets"."isVisible" = $2
and "assets"."fileCreatedAt" is not null
and "assets"."fileModifiedAt" is not null
and "assets"."localDateTime" is not null
@@ -303,17 +302,16 @@ from
"asset_stack"."id"
) as "stacked_assets" on "asset_stack"."id" is not null
where
"assets"."fileCreatedAt" <= $2
and (
(
"asset_stack"."primaryAssetId" = "assets"."id"
or "assets"."stackId" is null
)
and "assets"."deletedAt" is null
and "assets"."isVisible" = $3
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($4, "localDateTime" at time zone 'UTC') at time zone 'UTC' = $5
and date_trunc($3, "localDateTime" at time zone 'UTC') at time zone 'UTC' = $4
order by
"assets"."localDateTime" desc

5 changes: 0 additions & 5 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
@@ -49,8 +49,6 @@ import { anyUuid, asUuid, mapUpsertColumns } from 'src/utils/database';
import { globToSqlPattern } from 'src/utils/misc';
import { Paginated, PaginationOptions, paginationHelper } from 'src/utils/pagination';

const ASSET_CUTOFF_DATE = new Date('9000-01-01');

@Injectable()
export class AssetRepository implements IAssetRepository {
constructor(@InjectKysely() private db: Kysely<DB>) {}
@@ -607,7 +605,6 @@ export class AssetRepository implements IAssetRepository {
return this.db
.selectFrom('assets')
.selectAll('assets')
.where('assets.fileCreatedAt', '<=', ASSET_CUTOFF_DATE)
.$call(withExif)
.where('ownerId', '=', anyUuid(userIds))
.where('isVisible', '=', true)
@@ -626,7 +623,6 @@ export class AssetRepository implements IAssetRepository {
.with('assets', (qb) =>
qb
.selectFrom('assets')
.where('assets.fileCreatedAt', '<=', ASSET_CUTOFF_DATE)
.select(truncatedDate<Date>(options.size).as('timeBucket'))
.$if(!!options.isTrashed, (qb) => qb.where('assets.status', '!=', AssetStatus.DELETED))
.where('assets.deletedAt', options.isTrashed ? 'is not' : 'is', null)
@@ -680,7 +676,6 @@ export class AssetRepository implements IAssetRepository {
async getTimeBucket(timeBucket: string, options: TimeBucketOptions): Promise<AssetEntity[]> {
return hasPeople(this.db, options.personId ? [options.personId] : undefined)
.selectAll('assets')
.where('assets.fileCreatedAt', '<=', ASSET_CUTOFF_DATE)
.$call(withExif)
.$if(!!options.albumId, (qb) => withAlbums(qb, { albumId: options.albumId }))
.$if(!!options.userIds, (qb) => qb.where('assets.ownerId', '=', anyUuid(options.userIds!)))
8 changes: 3 additions & 5 deletions server/src/services/library.service.ts
Original file line number Diff line number Diff line change
@@ -25,8 +25,6 @@ import { mimeTypes } from 'src/utils/mime-types';
import { handlePromiseError } from 'src/utils/misc';
import { usePagination } from 'src/utils/pagination';

const ASSET_IMPORT_DATE = new Date('9999-12-31');

@Injectable()
export class LibraryService extends BaseService {
private watchLibraries = false;
@@ -381,9 +379,9 @@ export class LibraryService extends BaseService {
checksum: this.cryptoRepository.hashSha1(`path:${assetPath}`),
originalPath: assetPath,

fileCreatedAt: ASSET_IMPORT_DATE,
fileModifiedAt: ASSET_IMPORT_DATE,
localDateTime: ASSET_IMPORT_DATE,
fileCreatedAt: null,
fileModifiedAt: null,
localDateTime: null,
// TODO: device asset id is deprecated, remove it
deviceAssetId: `${basename(assetPath)}`.replaceAll(/\s+/g, ''),
deviceId: 'Library Import',
32 changes: 7 additions & 25 deletions server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import { firstDateTime } from 'exiftool-vendored/dist/FirstDateTime';
import { Insertable } from 'kysely';
import _ from 'lodash';
import { Duration } from 'luxon';
import { Stats } from 'node:fs';
import { constants } from 'node:fs/promises';
import path from 'node:path';
import { SystemConfig } from 'src/config';
@@ -172,22 +171,13 @@ export class MetadataService extends BaseService {
asset.fileModifiedAt = stats.mtime;
}

const { dateTimeOriginal, localDateTime, timeZone, modifyDate, fileCreatedAt, fileModifiedAt } = this.getDates(
asset,
exifTags,
stats,
);
const { dateTimeOriginal, localDateTime, timeZone, modifyDate } = this.getDates(asset, exifTags);
const { latitude, longitude, country, state, city } = await this.getGeo(exifTags, reverseGeocoding);

const { width, height } = this.getImageDimensions(exifTags);

let fileCreatedAtDate = dateTimeOriginal;
let fileModifiedAtDate = modifyDate;

if (asset.isExternal) {
fileCreatedAtDate = fileCreatedAt;
fileModifiedAtDate = fileModifiedAt;
}
const fileCreatedAtDate = dateTimeOriginal;
const fileModifiedAtDate = modifyDate;

const exifData: Insertable<Exif> = {
assetId: asset.id,
@@ -483,7 +473,7 @@ export class MetadataService extends BaseService {
asset.fileModifiedAt = stat.mtime;
}

const dates = this.getDates(asset, tags, stat);
const dates = this.getDates(asset, tags);
motionAsset = await this.assetRepository.create({
id: motionAssetId,
libraryId: asset.libraryId,
@@ -601,7 +591,7 @@ export class MetadataService extends BaseService {
}
}

private getDates(asset: AssetEntity, exifTags: ImmichTags, stat: Stats): AssetDatesDto {
private getDates(asset: AssetEntity, exifTags: ImmichTags): AssetDatesDto {
// We first assert that fileCreatedAt and fileModifiedAt are not null since that should be set to a non-null value before calling this function
if (asset.fileCreatedAt == null) {
this.logger.warn(`Asset ${asset.id} has no file creation date`);
@@ -629,16 +619,8 @@ export class MetadataService extends BaseService {
this.logger.verbose(`Asset ${asset.id} has no time zone information`);
}

let fileCreatedAt = asset.fileCreatedAt;
let fileModifiedAt = asset.fileModifiedAt;

if (asset.isExternal) {
// With external assets we need to extract dates from the filesystem, this can't be done with uploades assets as that information is lost on upload
fileCreatedAt = stat.mtime;
fileModifiedAt = stat.mtime;

this.logger.verbose(`External asset ${asset.id} has a file modification time of ${fileCreatedAt.toISOString()}`);
}
const fileCreatedAt = asset.fileCreatedAt;
const fileModifiedAt = asset.fileModifiedAt;

let dateTimeOriginal = dateTime?.toDate();
let localDateTime = dateTime?.toDateTime().setZone('UTC', { keepLocalTime: true }).toJSDate();

0 comments on commit 2504dbb

Please sign in to comment.