1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-11-23 22:24:44 +02:00

fixing experiment to regenerate db when switching sql driver #299

This commit is contained in:
Patrik J. Braun
2022-02-22 23:50:28 +01:00
parent b1f094c150
commit ca16ce0c83
4 changed files with 59 additions and 30 deletions

View File

@@ -62,17 +62,23 @@ export class Benchmark {
request: any;
beforeEach: () => Promise<any>;
afterEach: () => Promise<any>;
beforeAll: () => Promise<any>;
afterAll: () => Promise<any>;
private readonly bmExpressApp: BMExpressApp;
constructor(name: string,
request: any = {},
beforeEach?: () => Promise<any>,
afterEach?: () => Promise<any>) {
afterEach?: () => Promise<any>,
beforeAll?: () => Promise<any>,
afterAll?: () => Promise<any>) {
this.name = name;
this.request = request;
this.beforeEach = beforeEach;
this.afterEach = afterEach;
this.beforeAll = beforeAll;
this.afterAll = afterAll;
this.bmExpressApp = new BMExpressApp(this);
}
@@ -85,7 +91,13 @@ export class Benchmark {
for (const exp of Object.values(Experiments)) {
for (const group of Object.values(exp.groups)) {
ActiveExperiments[exp.name] = group;
if (this.beforeAll) {
await this.beforeAll();
}
ret.push(await this.runAnExperiment(RUNS));
if (this.afterAll) {
await this.afterAll();
}
ret[ret.length - 1].experiment = exp.name + '=' + group;
}
delete ActiveExperiments[exp.name];

View File

@@ -84,10 +84,13 @@ export class BenchmarkRunner {
}
async bmSaveDirectory(): Promise<BenchmarkResult[]> {
await this.init();
await this.resetDB();
const dir = await DiskMangerWorker.scanDirectory(this.biggestDirPath);
const bm = new Benchmark('Saving directory to DB', null, (): Promise<void> => this.resetDB());
const bm = new Benchmark('Saving directory to DB', null,
(): Promise<void> => this.resetDB(), null,
async (): Promise<void> => {
await this.init();
await this.setupDB();
});
bm.addAStep({
name: 'Saving directory to DB',
fn: (): Promise<void> => {
@@ -100,7 +103,11 @@ export class BenchmarkRunner {
async bmScanDirectory(): Promise<BenchmarkResult[]> {
await this.init();
const bm = new Benchmark('Scanning directory');
const bm = new Benchmark('Scanning directory', {}, null,
null,
async (): Promise<void> => {
await this.init();
});
bm.addAStep({
name: 'Scanning directory',
fn: async (): Promise<ContentWrapper> => new ContentWrapper(await DiskMangerWorker.scanDirectory(this.biggestDirPath))
@@ -109,27 +116,31 @@ export class BenchmarkRunner {
}
async bmListDirectory(): Promise<BenchmarkResult[]> {
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
await this.init();
await this.setupDB();
const req = Utils.clone(this.requestTemplate);
req.params.directory = this.biggestDirPath;
const bm = new Benchmark('List directory', req,
async (): Promise<void> => {
await ObjectManagers.reset();
await ObjectManagers.InitSQLManagers();
}, null,
async (): Promise<void> => {
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
await this.init();
await this.setupDB();
});
BMGalleryRouter.addDirectoryList(bm.BmExpressApp);
return await bm.run(this.RUNS);
}
async bmListPersons(): Promise<BenchmarkResult[]> {
await this.setupDB();
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise<void> => {
await ObjectManagers.reset();
await ObjectManagers.InitSQLManagers();
});
await ObjectManagers.reset();
await ObjectManagers.InitSQLManagers();
}, null,
async (): Promise<void> => {
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
await this.setupDB();
});
BMPersonRouter.addGetPersons(bm.BmExpressApp);
return await bm.run(this.RUNS);
}
@@ -234,7 +245,10 @@ export class BenchmarkRunner {
const req = Utils.clone(this.requestTemplate);
req.params.searchQueryDTO = JSON.stringify(entry.query);
const bm = new Benchmark('Searching for `' + entry.description + '`', req);
const bm = new Benchmark('Searching for `' + entry.description + '`', req, null, null,
async (): Promise<void> => {
await this.setupDB();
});
BMGalleryRouter.addSearch(bm.BmExpressApp);
results.push({result: await bm.run(this.RUNS), searchQuery: entry.query});
@@ -244,10 +258,12 @@ export class BenchmarkRunner {
async bmAutocomplete(text: string): Promise<BenchmarkResult[]> {
await this.setupDB();
const req = Utils.clone(this.requestTemplate);
req.params.text = text;
const bm = new Benchmark('Auto complete for `' + text + '`', req);
const bm = new Benchmark('Auto complete for `' + text + '`', req, null, null,
async (): Promise<void> => {
await this.setupDB();
});
BMGalleryRouter.addAutoComplete(bm.BmExpressApp);
return await bm.run(this.RUNS);
}

View File

@@ -2,7 +2,6 @@ export const Experiments = {
db: {
name: 'SQlite',
groups: {
sqlite3: 'sqlite3',
betterSqlite: 'better-sqlite'
}
}