From 09230b9e550e83306c7029cc2422dd4472b35305 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Wed, 12 May 2021 12:35:16 +0200 Subject: [PATCH] Adding indexes and proper character set to Media metadata to improve search performance --- .../database/sql/enitites/DirectoryEntity.ts | 1 + .../model/database/sql/enitites/MediaEntity.ts | 16 +++++++++++++++- .../model/database/sql/enitites/PhotoEntity.ts | 11 ++++++++++- src/common/DataStructureVersion.ts | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/backend/model/database/sql/enitites/DirectoryEntity.ts b/src/backend/model/database/sql/enitites/DirectoryEntity.ts index a4dcada5..74a78705 100644 --- a/src/backend/model/database/sql/enitites/DirectoryEntity.ts +++ b/src/backend/model/database/sql/enitites/DirectoryEntity.ts @@ -54,6 +54,7 @@ export class DirectoryEntity implements DirectoryDTO { @OneToMany(type => DirectoryEntity, dir => dir.parent) public directories: DirectoryEntity[]; + // not saving to database, it is only assigned when querying the DB public preview: MediaEntity; @OneToMany(type => MediaEntity, media => media.directory) diff --git a/src/backend/model/database/sql/enitites/MediaEntity.ts b/src/backend/model/database/sql/enitites/MediaEntity.ts index f766bd85..8e6f48ab 100644 --- a/src/backend/model/database/sql/enitites/MediaEntity.ts +++ b/src/backend/model/database/sql/enitites/MediaEntity.ts @@ -17,12 +17,19 @@ export class MediaDimensionEntity implements MediaDimension { export class MediaMetadataEntity implements MediaMetadata { + + @Index() @Column('text') caption: string; @Column(type => MediaDimensionEntity) size: MediaDimensionEntity; + /** + * Date in local timezone + * Reason: If you look back your holiday photos from a different timezone, + * you do not want to see 2AM next to a photo that was taken during lunch + */ @Column('bigint', { unsigned: true, transformer: { from: v => parseInt(v, 10), @@ -34,6 +41,7 @@ export class MediaMetadataEntity implements MediaMetadata { @Column('int', {unsigned: true}) fileSize: number; + @Index() @Column({ type: 'simple-array', charset: columnCharsetCS.charset, @@ -47,6 +55,7 @@ export class MediaMetadataEntity implements MediaMetadata { @Column(type => PositionMetaDataEntity) positionData: PositionMetaDataEntity; + @Index() @Column('tinyint', {unsigned: true}) rating: 0 | 1 | 2 | 3 | 4 | 5; @@ -56,12 +65,16 @@ export class MediaMetadataEntity implements MediaMetadata { @OneToMany(type => FaceRegionEntry, faceRegion => faceRegion.media) faces: FaceRegionEntry[]; + /** + * Caches the list of persons. Only used for searching + */ + @Index() @Column({ type: 'simple-array', select: false, nullable: true, charset: columnCharsetCS.charset, collation: columnCharsetCS.collation }) - persons: string[]; // Caches the list of persons. Only used for searching + persons: string[]; @Column('int', {unsigned: true}) bitRate: number; @@ -81,6 +94,7 @@ export abstract class MediaEntity implements MediaDTO { @PrimaryGeneratedColumn({unsigned: true}) id: number; + @Index() @Column(columnCharsetCS) name: string; diff --git a/src/backend/model/database/sql/enitites/PhotoEntity.ts b/src/backend/model/database/sql/enitites/PhotoEntity.ts index fa23058d..f04368b5 100644 --- a/src/backend/model/database/sql/enitites/PhotoEntity.ts +++ b/src/backend/model/database/sql/enitites/PhotoEntity.ts @@ -1,6 +1,7 @@ -import {ChildEntity, Column} from 'typeorm'; +import {ChildEntity, Column, Index} from 'typeorm'; import {CameraMetadata, GPSMetadata, PhotoDTO, PhotoMetadata, PositionMetaData} from '../../../../../common/entities/PhotoDTO'; import {MediaEntity, MediaMetadataEntity} from './MediaEntity'; +import {columnCharsetCS} from './EntityUtils'; export class CameraMetadataEntity implements CameraMetadata { @@ -8,9 +9,11 @@ export class CameraMetadataEntity implements CameraMetadata { ISO: number; @Column('text', {nullable: true}) + @Column(columnCharsetCS) model: string; @Column('text', {nullable: true}) + @Column(columnCharsetCS) make: string; @Column('float', {nullable: true}) @@ -43,13 +46,19 @@ export class PositionMetaDataEntity implements PositionMetaData { @Column(type => GPSMetadataEntity) GPSData: GPSMetadataEntity; + @Index() @Column('text', {nullable: true}) + @Column(columnCharsetCS) country: string; + @Index() @Column('text', {nullable: true}) + @Column(columnCharsetCS) state: string; + @Index() @Column('text', {nullable: true}) + @Column(columnCharsetCS) city: string; } diff --git a/src/common/DataStructureVersion.ts b/src/common/DataStructureVersion.ts index 222e6c12..14f8adb1 100644 --- a/src/common/DataStructureVersion.ts +++ b/src/common/DataStructureVersion.ts @@ -1 +1 @@ -export const DataStructureVersion = 19; +export const DataStructureVersion = 20;