mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
Implementing .saved_searches.pg2conf saving tests
This commit is contained in:
parent
e26c60d67b
commit
404b82e12b
@ -51,6 +51,10 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indexes a dir, but returns early with the scanned version,
|
||||||
|
* does not wait for the DB to be saved
|
||||||
|
*/
|
||||||
public indexDirectory(relativeDirectoryName: string): Promise<DirectoryDTO> {
|
public indexDirectory(relativeDirectoryName: string): Promise<DirectoryDTO> {
|
||||||
return new Promise(async (resolve, reject): Promise<void> => {
|
return new Promise(async (resolve, reject): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
@ -62,14 +66,12 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
}
|
}
|
||||||
scannedDirectory.media.forEach((p): any[] => p.readyThumbnails = []);
|
scannedDirectory.media.forEach((p): any[] => p.readyThumbnails = []);
|
||||||
|
|
||||||
// filter server side pg2conf
|
|
||||||
const serverSideConfs = scannedDirectory.metaFile.filter(m => ServerPG2ConfMap[m.name]);
|
|
||||||
scannedDirectory.metaFile = scannedDirectory.metaFile.filter(m => !ServerPG2ConfMap[m.name]);
|
|
||||||
|
|
||||||
resolve(scannedDirectory);
|
const dirClone = Utils.shallowClone(scannedDirectory);
|
||||||
|
// filter server side only config from returning
|
||||||
|
dirClone.metaFile = dirClone.metaFile.filter(m => !ServerPG2ConfMap[m.name]);
|
||||||
|
|
||||||
// process server side pg2conf
|
resolve(dirClone);
|
||||||
await IndexingManager.processServerSidePG2Conf(serverSideConfs);
|
|
||||||
|
|
||||||
// save directory to DB
|
// save directory to DB
|
||||||
this.queueForSave(scannedDirectory).catch(console.error);
|
this.queueForSave(scannedDirectory).catch(console.error);
|
||||||
@ -94,7 +96,11 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Todo fix it, once typeorm support connection pools for sqlite
|
// Todo fix it, once typeorm support connection pools for sqlite
|
||||||
|
/**
|
||||||
|
* Queues up a directory to save to the DB.
|
||||||
|
*/
|
||||||
protected async queueForSave(scannedDirectory: DirectoryDTO): Promise<void> {
|
protected async queueForSave(scannedDirectory: DirectoryDTO): Promise<void> {
|
||||||
|
// Is this dir already queued for saving?
|
||||||
if (this.savingQueue.findIndex((dir): boolean => dir.name === scannedDirectory.name &&
|
if (this.savingQueue.findIndex((dir): boolean => dir.name === scannedDirectory.name &&
|
||||||
dir.path === scannedDirectory.path &&
|
dir.path === scannedDirectory.path &&
|
||||||
dir.lastModified === scannedDirectory.lastModified &&
|
dir.lastModified === scannedDirectory.lastModified &&
|
||||||
@ -357,12 +363,15 @@ export class IndexingManager implements IIndexingManager {
|
|||||||
this.isSaving = true;
|
this.isSaving = true;
|
||||||
try {
|
try {
|
||||||
const connection = await SQLConnection.getConnection();
|
const connection = await SQLConnection.getConnection();
|
||||||
|
const serverSideConfigs = scannedDirectory.metaFile.filter(m => ServerPG2ConfMap[m.name]);
|
||||||
|
scannedDirectory.metaFile = scannedDirectory.metaFile.filter(m => !ServerPG2ConfMap[m.name]);
|
||||||
const currentDirId: number = await this.saveParentDir(connection, scannedDirectory);
|
const currentDirId: number = await this.saveParentDir(connection, scannedDirectory);
|
||||||
await this.saveChildDirs(connection, currentDirId, scannedDirectory);
|
await this.saveChildDirs(connection, currentDirId, scannedDirectory);
|
||||||
await this.saveMedia(connection, currentDirId, scannedDirectory.media);
|
await this.saveMedia(connection, currentDirId, scannedDirectory.media);
|
||||||
await this.saveMetaFiles(connection, currentDirId, scannedDirectory);
|
await this.saveMetaFiles(connection, currentDirId, scannedDirectory);
|
||||||
await ObjectManagers.getInstance().PersonManager.onGalleryIndexUpdate();
|
await ObjectManagers.getInstance().PersonManager.onGalleryIndexUpdate();
|
||||||
await ObjectManagers.getInstance().VersionManager.updateDataVersion();
|
await ObjectManagers.getInstance().VersionManager.updateDataVersion();
|
||||||
|
await IndexingManager.processServerSidePG2Conf(serverSideConfigs);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -22,6 +22,7 @@ import {DatabaseType, ServerDataBaseConfig, SQLLogLevel} from '../../../../commo
|
|||||||
import {AlbumBaseEntity} from './enitites/album/AlbumBaseEntity';
|
import {AlbumBaseEntity} from './enitites/album/AlbumBaseEntity';
|
||||||
import {SavedSearchEntity} from './enitites/album/SavedSearchEntity';
|
import {SavedSearchEntity} from './enitites/album/SavedSearchEntity';
|
||||||
|
|
||||||
|
const LOG_TAG = '[SQLConnection]';
|
||||||
|
|
||||||
export class SQLConnection {
|
export class SQLConnection {
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ export class SQLConnection {
|
|||||||
if (Config.Server.Log.sqlLevel !== SQLLogLevel.none) {
|
if (Config.Server.Log.sqlLevel !== SQLLogLevel.none) {
|
||||||
options.logging = SQLLogLevel[Config.Server.Log.sqlLevel];
|
options.logging = SQLLogLevel[Config.Server.Log.sqlLevel];
|
||||||
}
|
}
|
||||||
|
Logger.debug(LOG_TAG, 'Creating connection: ' + DatabaseType[Config.Server.Database.type]);
|
||||||
this.connection = await this.createConnection(options);
|
this.connection = await this.createConnection(options);
|
||||||
await SQLConnection.schemeSync(this.connection);
|
await SQLConnection.schemeSync(this.connection);
|
||||||
}
|
}
|
||||||
@ -131,7 +132,7 @@ export class SQLConnection {
|
|||||||
return await createConnection(options);
|
return await createConnection(options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.sqlMessage === 'Unknown database \'' + options.database + '\'') {
|
if (e.sqlMessage === 'Unknown database \'' + options.database + '\'') {
|
||||||
Logger.debug('creating database: ' + options.database);
|
Logger.debug(LOG_TAG, 'creating database: ' + options.database);
|
||||||
const tmpOption = Utils.clone(options);
|
const tmpOption = Utils.clone(options);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
delete tmpOption.database;
|
delete tmpOption.database;
|
||||||
@ -153,7 +154,7 @@ export class SQLConnection {
|
|||||||
if (version && version.version === DataStructureVersion) {
|
if (version && version.version === DataStructureVersion) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logger.info('Updating database scheme');
|
Logger.info(LOG_TAG, 'Updating database scheme');
|
||||||
if (!version) {
|
if (!version) {
|
||||||
version = new VersionEntity();
|
version = new VersionEntity();
|
||||||
}
|
}
|
||||||
@ -173,7 +174,7 @@ export class SQLConnection {
|
|||||||
await connection.dropDatabase();
|
await connection.dropDatabase();
|
||||||
await connection.synchronize();
|
await connection.synchronize();
|
||||||
await connection.getRepository(VersionEntity).save(version);
|
await connection.getRepository(VersionEntity).save(version);
|
||||||
Logger.warn('Could not move users to the new db scheme, deleting them. Details:' + e.toString());
|
Logger.warn(LOG_TAG, 'Could not move users to the new db scheme, deleting them. Details:' + e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,14 @@ export class Utils {
|
|||||||
return JSON.parse(JSON.stringify(object));
|
return JSON.parse(JSON.stringify(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static shallowClone<T>(object: T): T {
|
||||||
|
const c: any = {};
|
||||||
|
for (const e of Object.entries(object)) {
|
||||||
|
c[e[0]] = [1];
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
static zeroPrefix(value: string | number, length: number): string {
|
static zeroPrefix(value: string | number, length: number): string {
|
||||||
const ret = '00000' + value;
|
const ret = '00000' + value;
|
||||||
return ret.substr(ret.length - length);
|
return ret.substr(ret.length - length);
|
||||||
|
@ -299,7 +299,7 @@ export class ServerPhotoConfig {
|
|||||||
export class ServerMediaConfig {
|
export class ServerMediaConfig {
|
||||||
@ConfigProperty({description: 'Images are loaded from this folder (read permission required)'})
|
@ConfigProperty({description: 'Images are loaded from this folder (read permission required)'})
|
||||||
folder: string = 'demo/images';
|
folder: string = 'demo/images';
|
||||||
@ConfigProperty({description: 'Thumbnails, coverted photos, videos will be stored here (write permission required)'})
|
@ConfigProperty({description: 'Thumbnails, converted photos, videos will be stored here (write permission required)'})
|
||||||
tempFolder: string = 'demo/tmp';
|
tempFolder: string = 'demo/tmp';
|
||||||
@ConfigProperty()
|
@ConfigProperty()
|
||||||
Video: ServerVideoConfig = new ServerVideoConfig();
|
Video: ServerVideoConfig = new ServerVideoConfig();
|
||||||
|
@ -96,7 +96,6 @@ export class GallerySearchComponent implements OnDestroy {
|
|||||||
|
|
||||||
|
|
||||||
onQueryChange(): void {
|
onQueryChange(): void {
|
||||||
console.log('cahnge', this.searchQueryDTO);
|
|
||||||
this.rawSearchText = this.searchQueryParserService.stringify(this.searchQueryDTO);
|
this.rawSearchText = this.searchQueryParserService.stringify(this.searchQueryDTO);
|
||||||
// this.validateRawSearchText();
|
// this.validateRawSearchText();
|
||||||
}
|
}
|
||||||
|
10
test/backend/assets/.saved_searches.pg2conf
Normal file
10
test/backend/assets/.saved_searches.pg2conf
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Alvin",
|
||||||
|
"searchQuery": {
|
||||||
|
"type": 105,
|
||||||
|
"text": "Alvin",
|
||||||
|
"matchType": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -11,11 +11,14 @@ import {MediaDTO} from '../../../../../src/common/entities/MediaDTO';
|
|||||||
import {FileDTO} from '../../../../../src/common/entities/FileDTO';
|
import {FileDTO} from '../../../../../src/common/entities/FileDTO';
|
||||||
import {IndexingManager} from '../../../../../src/backend/model/database/sql/IndexingManager';
|
import {IndexingManager} from '../../../../../src/backend/model/database/sql/IndexingManager';
|
||||||
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
||||||
import {PersonManager} from '../../../../../src/backend/model/database/sql/PersonManager';
|
|
||||||
import {DBTestHelper} from '../../../DBTestHelper';
|
import {DBTestHelper} from '../../../DBTestHelper';
|
||||||
import {VersionManager} from '../../../../../src/backend/model/database/sql/VersionManager';
|
|
||||||
import {DiskMangerWorker} from '../../../../../src/backend/model/threading/DiskMangerWorker';
|
import {DiskMangerWorker} from '../../../../../src/backend/model/threading/DiskMangerWorker';
|
||||||
import {ReIndexingSensitivity} from '../../../../../src/common/config/private/PrivateConfig';
|
import {ReIndexingSensitivity} from '../../../../../src/common/config/private/PrivateConfig';
|
||||||
|
import {AlbumManager} from '../../../../../src/backend/model/database/sql/AlbumManager';
|
||||||
|
import {SearchQueryTypes, TextSearch, TextSearchQueryMatchTypes} from '../../../../../src/common/entities/SearchQueryDTO';
|
||||||
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
||||||
|
import * as path from 'path';
|
||||||
|
import {DiskManager} from '../../../../../src/backend/model/DiskManger';
|
||||||
|
|
||||||
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
|
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
|
||||||
const chai = require('chai');
|
const chai = require('chai');
|
||||||
@ -59,12 +62,13 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await sqlHelper.initDB();
|
await sqlHelper.initDB();
|
||||||
ObjectManagers.getInstance().PersonManager = new PersonManager();
|
// ObjectManagers.getInstance().PersonManager = new PersonManager();
|
||||||
ObjectManagers.getInstance().VersionManager = new VersionManager();
|
// ObjectManagers.getInstance().VersionManager = new VersionManager();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
after(async () => {
|
afterEach(async () => {
|
||||||
|
Config.loadSync();
|
||||||
await sqlHelper.clearDB();
|
await sqlHelper.clearDB();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -472,7 +476,6 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
|||||||
.to.deep.equalInAnyOrder(Utils.clone(Utils.removeNullOrEmptyObj(parent)));
|
.to.deep.equalInAnyOrder(Utils.clone(Utils.removeNullOrEmptyObj(parent)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should reset DB', async () => {
|
it('should reset DB', async () => {
|
||||||
const gm = new GalleryManagerTest();
|
const gm = new GalleryManagerTest();
|
||||||
const im = new IndexingManagerTest();
|
const im = new IndexingManagerTest();
|
||||||
@ -574,4 +577,34 @@ describe('IndexingManager', (sqlHelper: DBTestHelper) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
DBTestHelper.savedDescribe('should index .pg2conf', () => {
|
||||||
|
|
||||||
|
|
||||||
|
it('.saved_searches.pg2conf', async () => {
|
||||||
|
Config.Server.Threading.enabled = false;
|
||||||
|
|
||||||
|
Config.Server.Media.folder = path.join(__dirname, '/../../../assets');
|
||||||
|
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
|
||||||
|
const im = new IndexingManagerTest();
|
||||||
|
const am = new AlbumManager();
|
||||||
|
const dir = await DiskManager.scanDirectory('/');
|
||||||
|
await im.saveToDB(dir);
|
||||||
|
const albums = await am.getAlbums();
|
||||||
|
expect(albums[0].preview).to.be.an('object');
|
||||||
|
delete albums[0].preview;
|
||||||
|
expect(albums).to.be.equalInAnyOrder([
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'Alvin',
|
||||||
|
locked: true,
|
||||||
|
searchQuery: {
|
||||||
|
type: SearchQueryTypes.person,
|
||||||
|
text: 'Alvin',
|
||||||
|
matchType: TextSearchQueryMatchTypes.like
|
||||||
|
} as TextSearch
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user