1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-18 04:58:59 +02:00

Implement youngest and oldest photo date for directories

This commit is contained in:
Patrik J. Braun 2023-09-11 13:19:51 +02:00
parent 7ec6725c59
commit 8c083ed59b
9 changed files with 55 additions and 16 deletions

View File

@ -208,6 +208,8 @@ export class IndexingManager {
currentDir.lastModified = scannedDirectory.lastModified;
currentDir.lastScanned = scannedDirectory.lastScanned;
currentDir.mediaCount = scannedDirectory.mediaCount;
currentDir.youngestMedia = scannedDirectory.youngestMedia;
currentDir.oldestMedia = scannedDirectory.oldestMedia;
await directoryRepository.save(currentDir);
return currentDir.id;
} else {
@ -216,6 +218,8 @@ export class IndexingManager {
mediaCount: scannedDirectory.mediaCount,
lastModified: scannedDirectory.lastModified,
lastScanned: scannedDirectory.lastScanned,
youngestMedia: scannedDirectory.youngestMedia,
oldestMedia: scannedDirectory.oldestMedia,
name: scannedDirectory.name,
path: scannedDirectory.path,
} as DirectoryEntity)

View File

@ -64,6 +64,24 @@ export class DirectoryEntity
@Column('mediumint', { unsigned: true })
mediaCount: number;
@Column('bigint', {
nullable: true,
transformer: {
from: (v) => parseInt(v, 10),
to: (v) => v,
},
})
oldestMedia: number;
@Column('bigint', {
nullable: true,
transformer: {
from: (v) => parseInt(v, 10),
to: (v) => v,
},
})
youngestMedia: number;
@Index()
@ManyToOne((type) => DirectoryEntity, (directory) => directory.directories, {
onDelete: 'CASCADE',

View File

@ -1,9 +1,6 @@
import {promises as fsp, Stats} from 'fs';
import * as path from 'path';
import {
ParentDirectoryDTO,
SubDirectoryDTO,
} from '../../../common/entities/DirectoryDTO';
import {ParentDirectoryDTO, SubDirectoryDTO,} from '../../../common/entities/DirectoryDTO';
import {PhotoDTO} from '../../../common/entities/PhotoDTO';
import {ProjectPath} from '../../ProjectPath';
import {Config} from '../../../common/config/private/Config';
@ -120,15 +117,17 @@ export class DiskMangerWorker {
name: directoryName,
path: directoryParent,
lastModified: this.calcLastModified(stat),
lastScanned: Date.now(),
directories: [],
isPartial: false,
isPartial: settings.coverOnly === true,
mediaCount: 0,
cover: null,
validCover: false,
media: [],
metaFile: [],
};
if (!settings.coverOnly) {
directory.lastScanned = Date.now();
}
// nothing to scan, we are here for the empty dir
if (
@ -164,9 +163,6 @@ export class DiskMangerWorker {
}
)) as SubDirectoryDTO;
d.lastScanned = 0; // it was not a fully scanned
d.isPartial = true;
directory.directories.push(d);
} else if (PhotoProcessing.isPhoto(fullFilePath)) {
if (settings.noPhoto === true) {
@ -239,6 +235,16 @@ export class DiskMangerWorker {
}
directory.mediaCount = directory.media.length;
if (!directory.isPartial) {
directory.youngestMedia = Number.MAX_SAFE_INTEGER;
directory.oldestMedia = Number.MIN_SAFE_INTEGER;
directory.media.forEach((m) => {
directory.youngestMedia = Math.min(m.metadata.creationDate, directory.youngestMedia);
directory.oldestMedia = Math.max(m.metadata.creationDate, directory.oldestMedia);
}
);
}
return directory;
}

View File

@ -1,4 +1,4 @@
/**
* This version indicates that the sql/entities/*Entity.ts files got changed and the db needs to be recreated
*/
export const DataStructureVersion = 32;
export const DataStructureVersion = 33;

View File

@ -16,11 +16,12 @@ export interface DirectoryBaseDTO<S extends FileDTO = MediaDTO>
name: string;
path: string;
lastModified: number;
lastScanned: number;
lastScanned?: number;
isPartial?: boolean;
parent: DirectoryBaseDTO<S>;
mediaCount: number;
youngestMedia?: number;
oldestMedia?: number;
directories?: DirectoryBaseDTO<S>[];
media?: S[];
metaFile?: FileDTO[];
@ -34,10 +35,12 @@ export interface ParentDirectoryDTO<S extends FileDTO = MediaDTO>
name: string;
path: string;
lastModified: number;
lastScanned: number;
lastScanned?: number;
isPartial?: boolean;
parent: ParentDirectoryDTO<S>;
mediaCount: number;
youngestMedia?: number;
oldestMedia?: number;
directories: SubDirectoryDTO<S>[];
media: S[];
metaFile: FileDTO[];

View File

@ -1,4 +1,4 @@
import { DirectoryPathDTO } from './DirectoryDTO';
import {DirectoryPathDTO} from './DirectoryDTO';
export interface FileDTO {
id: number;

View File

@ -10,12 +10,12 @@ import {VideoEntity, VideoMetadataEntity} from '../src/backend/model/database/en
import {MediaDimension, MediaDTO} from '../src/common/entities/MediaDTO';
import {
CameraMetadata,
CoverPhotoDTO,
FaceRegion,
GPSMetadata,
PhotoDTO,
PhotoMetadata,
PositionMetaData,
CoverPhotoDTO
PositionMetaData
} from '../src/common/entities/PhotoDTO';
import {DirectoryBaseDTO, DirectoryPathDTO} from '../src/common/entities/DirectoryDTO';
import {FileDTO} from '../src/common/entities/FileDTO';
@ -31,6 +31,8 @@ export class TestHelper {
dir.name = name;
dir.path = DiskMangerWorker.pathFromParent({path: '', name: '.'});
dir.mediaCount = 0;
dir.youngestMedia = 10;
dir.oldestMedia = 1000;
dir.directories = [];
dir.metaFile = [];
dir.media = [];
@ -272,6 +274,8 @@ export class TestHelper {
name: DiskMangerWorker.dirName(forceStr || Math.random().toString(36).substring(7)),
path: DiskMangerWorker.pathFromParent({path: '', name: '.'}),
mediaCount: 0,
youngestMedia: 10,
oldestMedia: 1000,
directories: [],
metaFile: [],
cover: null,

View File

@ -147,6 +147,8 @@ describe('CoverManager', (sqlHelper: DBTestHelper) => {
delete (ret.directory as DirectoryBaseDTO).lastScanned;
delete (ret.directory as DirectoryBaseDTO).lastModified;
delete (ret.directory as DirectoryBaseDTO).mediaCount;
delete (ret.directory as DirectoryBaseDTO).youngestMedia;
delete (ret.directory as DirectoryBaseDTO).oldestMedia;
delete (ret as PhotoDTO).metadata;
tmpDir.directories = tmpD;
tmpDir.media = tmpM;

View File

@ -229,6 +229,8 @@ describe('SearchManager', (sqlHelper: DBTestHelper) => {
delete (ret.directory as DirectoryBaseDTO).lastScanned;
delete (ret.directory as DirectoryBaseDTO).lastModified;
delete (ret.directory as DirectoryBaseDTO).mediaCount;
delete (ret.directory as DirectoryBaseDTO).youngestMedia;
delete (ret.directory as DirectoryBaseDTO).oldestMedia;
if ((ret as PhotoDTO).metadata &&
((ret as PhotoDTO).metadata as PhotoMetadata).faces && !((ret as PhotoDTO).metadata as PhotoMetadata).faces.length) {
delete ((ret as PhotoDTO).metadata as PhotoMetadata).faces;