1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Adding indexes and proper character set to Media metadata to improve search performance

This commit is contained in:
Patrik J. Braun 2021-05-12 12:35:16 +02:00
parent 872e63703d
commit 09230b9e55
4 changed files with 27 additions and 3 deletions

View File

@ -54,6 +54,7 @@ export class DirectoryEntity implements DirectoryDTO {
@OneToMany(type => DirectoryEntity, dir => dir.parent) @OneToMany(type => DirectoryEntity, dir => dir.parent)
public directories: DirectoryEntity[]; public directories: DirectoryEntity[];
// not saving to database, it is only assigned when querying the DB
public preview: MediaEntity; public preview: MediaEntity;
@OneToMany(type => MediaEntity, media => media.directory) @OneToMany(type => MediaEntity, media => media.directory)

View File

@ -17,12 +17,19 @@ export class MediaDimensionEntity implements MediaDimension {
export class MediaMetadataEntity implements MediaMetadata { export class MediaMetadataEntity implements MediaMetadata {
@Index()
@Column('text') @Column('text')
caption: string; caption: string;
@Column(type => MediaDimensionEntity) @Column(type => MediaDimensionEntity)
size: 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', { @Column('bigint', {
unsigned: true, transformer: { unsigned: true, transformer: {
from: v => parseInt(v, 10), from: v => parseInt(v, 10),
@ -34,6 +41,7 @@ export class MediaMetadataEntity implements MediaMetadata {
@Column('int', {unsigned: true}) @Column('int', {unsigned: true})
fileSize: number; fileSize: number;
@Index()
@Column({ @Column({
type: 'simple-array', type: 'simple-array',
charset: columnCharsetCS.charset, charset: columnCharsetCS.charset,
@ -47,6 +55,7 @@ export class MediaMetadataEntity implements MediaMetadata {
@Column(type => PositionMetaDataEntity) @Column(type => PositionMetaDataEntity)
positionData: PositionMetaDataEntity; positionData: PositionMetaDataEntity;
@Index()
@Column('tinyint', {unsigned: true}) @Column('tinyint', {unsigned: true})
rating: 0 | 1 | 2 | 3 | 4 | 5; rating: 0 | 1 | 2 | 3 | 4 | 5;
@ -56,12 +65,16 @@ export class MediaMetadataEntity implements MediaMetadata {
@OneToMany(type => FaceRegionEntry, faceRegion => faceRegion.media) @OneToMany(type => FaceRegionEntry, faceRegion => faceRegion.media)
faces: FaceRegionEntry[]; faces: FaceRegionEntry[];
/**
* Caches the list of persons. Only used for searching
*/
@Index()
@Column({ @Column({
type: 'simple-array', select: false, nullable: true, type: 'simple-array', select: false, nullable: true,
charset: columnCharsetCS.charset, charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation collation: columnCharsetCS.collation
}) })
persons: string[]; // Caches the list of persons. Only used for searching persons: string[];
@Column('int', {unsigned: true}) @Column('int', {unsigned: true})
bitRate: number; bitRate: number;
@ -81,6 +94,7 @@ export abstract class MediaEntity implements MediaDTO {
@PrimaryGeneratedColumn({unsigned: true}) @PrimaryGeneratedColumn({unsigned: true})
id: number; id: number;
@Index()
@Column(columnCharsetCS) @Column(columnCharsetCS)
name: string; name: string;

View File

@ -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 {CameraMetadata, GPSMetadata, PhotoDTO, PhotoMetadata, PositionMetaData} from '../../../../../common/entities/PhotoDTO';
import {MediaEntity, MediaMetadataEntity} from './MediaEntity'; import {MediaEntity, MediaMetadataEntity} from './MediaEntity';
import {columnCharsetCS} from './EntityUtils';
export class CameraMetadataEntity implements CameraMetadata { export class CameraMetadataEntity implements CameraMetadata {
@ -8,9 +9,11 @@ export class CameraMetadataEntity implements CameraMetadata {
ISO: number; ISO: number;
@Column('text', {nullable: true}) @Column('text', {nullable: true})
@Column(columnCharsetCS)
model: string; model: string;
@Column('text', {nullable: true}) @Column('text', {nullable: true})
@Column(columnCharsetCS)
make: string; make: string;
@Column('float', {nullable: true}) @Column('float', {nullable: true})
@ -43,13 +46,19 @@ export class PositionMetaDataEntity implements PositionMetaData {
@Column(type => GPSMetadataEntity) @Column(type => GPSMetadataEntity)
GPSData: GPSMetadataEntity; GPSData: GPSMetadataEntity;
@Index()
@Column('text', {nullable: true}) @Column('text', {nullable: true})
@Column(columnCharsetCS)
country: string; country: string;
@Index()
@Column('text', {nullable: true}) @Column('text', {nullable: true})
@Column(columnCharsetCS)
state: string; state: string;
@Index()
@Column('text', {nullable: true}) @Column('text', {nullable: true})
@Column(columnCharsetCS)
city: string; city: string;
} }

View File

@ -1 +1 @@
export const DataStructureVersion = 19; export const DataStructureVersion = 20;