You've already forked pigallery2
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:
@@ -62,17 +62,23 @@ export class Benchmark {
|
|||||||
request: any;
|
request: any;
|
||||||
beforeEach: () => Promise<any>;
|
beforeEach: () => Promise<any>;
|
||||||
afterEach: () => Promise<any>;
|
afterEach: () => Promise<any>;
|
||||||
|
beforeAll: () => Promise<any>;
|
||||||
|
afterAll: () => Promise<any>;
|
||||||
private readonly bmExpressApp: BMExpressApp;
|
private readonly bmExpressApp: BMExpressApp;
|
||||||
|
|
||||||
|
|
||||||
constructor(name: string,
|
constructor(name: string,
|
||||||
request: any = {},
|
request: any = {},
|
||||||
beforeEach?: () => Promise<any>,
|
beforeEach?: () => Promise<any>,
|
||||||
afterEach?: () => Promise<any>) {
|
afterEach?: () => Promise<any>,
|
||||||
|
beforeAll?: () => Promise<any>,
|
||||||
|
afterAll?: () => Promise<any>) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.beforeEach = beforeEach;
|
this.beforeEach = beforeEach;
|
||||||
this.afterEach = afterEach;
|
this.afterEach = afterEach;
|
||||||
|
this.beforeAll = beforeAll;
|
||||||
|
this.afterAll = afterAll;
|
||||||
this.bmExpressApp = new BMExpressApp(this);
|
this.bmExpressApp = new BMExpressApp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +91,13 @@ export class Benchmark {
|
|||||||
for (const exp of Object.values(Experiments)) {
|
for (const exp of Object.values(Experiments)) {
|
||||||
for (const group of Object.values(exp.groups)) {
|
for (const group of Object.values(exp.groups)) {
|
||||||
ActiveExperiments[exp.name] = group;
|
ActiveExperiments[exp.name] = group;
|
||||||
|
if (this.beforeAll) {
|
||||||
|
await this.beforeAll();
|
||||||
|
}
|
||||||
ret.push(await this.runAnExperiment(RUNS));
|
ret.push(await this.runAnExperiment(RUNS));
|
||||||
|
if (this.afterAll) {
|
||||||
|
await this.afterAll();
|
||||||
|
}
|
||||||
ret[ret.length - 1].experiment = exp.name + '=' + group;
|
ret[ret.length - 1].experiment = exp.name + '=' + group;
|
||||||
}
|
}
|
||||||
delete ActiveExperiments[exp.name];
|
delete ActiveExperiments[exp.name];
|
||||||
|
|||||||
@@ -84,10 +84,13 @@ export class BenchmarkRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async bmSaveDirectory(): Promise<BenchmarkResult[]> {
|
async bmSaveDirectory(): Promise<BenchmarkResult[]> {
|
||||||
await this.init();
|
|
||||||
await this.resetDB();
|
|
||||||
const dir = await DiskMangerWorker.scanDirectory(this.biggestDirPath);
|
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({
|
bm.addAStep({
|
||||||
name: 'Saving directory to DB',
|
name: 'Saving directory to DB',
|
||||||
fn: (): Promise<void> => {
|
fn: (): Promise<void> => {
|
||||||
@@ -100,7 +103,11 @@ export class BenchmarkRunner {
|
|||||||
|
|
||||||
async bmScanDirectory(): Promise<BenchmarkResult[]> {
|
async bmScanDirectory(): Promise<BenchmarkResult[]> {
|
||||||
await this.init();
|
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({
|
bm.addAStep({
|
||||||
name: 'Scanning directory',
|
name: 'Scanning directory',
|
||||||
fn: async (): Promise<ContentWrapper> => new ContentWrapper(await DiskMangerWorker.scanDirectory(this.biggestDirPath))
|
fn: async (): Promise<ContentWrapper> => new ContentWrapper(await DiskMangerWorker.scanDirectory(this.biggestDirPath))
|
||||||
@@ -109,26 +116,30 @@ export class BenchmarkRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async bmListDirectory(): Promise<BenchmarkResult[]> {
|
async bmListDirectory(): Promise<BenchmarkResult[]> {
|
||||||
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
|
||||||
await this.init();
|
|
||||||
await this.setupDB();
|
|
||||||
const req = Utils.clone(this.requestTemplate);
|
const req = Utils.clone(this.requestTemplate);
|
||||||
req.params.directory = this.biggestDirPath;
|
req.params.directory = this.biggestDirPath;
|
||||||
const bm = new Benchmark('List directory', req,
|
const bm = new Benchmark('List directory', req,
|
||||||
async (): Promise<void> => {
|
async (): Promise<void> => {
|
||||||
await ObjectManagers.reset();
|
await ObjectManagers.reset();
|
||||||
await ObjectManagers.InitSQLManagers();
|
await ObjectManagers.InitSQLManagers();
|
||||||
|
}, null,
|
||||||
|
async (): Promise<void> => {
|
||||||
|
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
||||||
|
await this.init();
|
||||||
|
await this.setupDB();
|
||||||
});
|
});
|
||||||
BMGalleryRouter.addDirectoryList(bm.BmExpressApp);
|
BMGalleryRouter.addDirectoryList(bm.BmExpressApp);
|
||||||
return await bm.run(this.RUNS);
|
return await bm.run(this.RUNS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bmListPersons(): Promise<BenchmarkResult[]> {
|
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> => {
|
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async (): Promise<void> => {
|
||||||
await ObjectManagers.reset();
|
await ObjectManagers.reset();
|
||||||
await ObjectManagers.InitSQLManagers();
|
await ObjectManagers.InitSQLManagers();
|
||||||
|
}, null,
|
||||||
|
async (): Promise<void> => {
|
||||||
|
Config.Server.Indexing.reIndexingSensitivity = ReIndexingSensitivity.low;
|
||||||
|
await this.setupDB();
|
||||||
});
|
});
|
||||||
BMPersonRouter.addGetPersons(bm.BmExpressApp);
|
BMPersonRouter.addGetPersons(bm.BmExpressApp);
|
||||||
return await bm.run(this.RUNS);
|
return await bm.run(this.RUNS);
|
||||||
@@ -234,7 +245,10 @@ export class BenchmarkRunner {
|
|||||||
const req = Utils.clone(this.requestTemplate);
|
const req = Utils.clone(this.requestTemplate);
|
||||||
req.params.searchQueryDTO = JSON.stringify(entry.query);
|
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);
|
BMGalleryRouter.addSearch(bm.BmExpressApp);
|
||||||
|
|
||||||
results.push({result: await bm.run(this.RUNS), searchQuery: entry.query});
|
results.push({result: await bm.run(this.RUNS), searchQuery: entry.query});
|
||||||
@@ -244,10 +258,12 @@ export class BenchmarkRunner {
|
|||||||
|
|
||||||
|
|
||||||
async bmAutocomplete(text: string): Promise<BenchmarkResult[]> {
|
async bmAutocomplete(text: string): Promise<BenchmarkResult[]> {
|
||||||
await this.setupDB();
|
|
||||||
const req = Utils.clone(this.requestTemplate);
|
const req = Utils.clone(this.requestTemplate);
|
||||||
req.params.text = text;
|
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);
|
BMGalleryRouter.addAutoComplete(bm.BmExpressApp);
|
||||||
return await bm.run(this.RUNS);
|
return await bm.run(this.RUNS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ export const Experiments = {
|
|||||||
db: {
|
db: {
|
||||||
name: 'SQlite',
|
name: 'SQlite',
|
||||||
groups: {
|
groups: {
|
||||||
sqlite3: 'sqlite3',
|
|
||||||
betterSqlite: 'better-sqlite'
|
betterSqlite: 'better-sqlite'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,6 @@ export class SQLConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async getConnection(): Promise<Connection> {
|
public static async getConnection(): Promise<Connection> {
|
||||||
if (ActiveExperiments[Experiments.db.name] === Experiments.db.groups.sqlite3) {
|
|
||||||
Config.Server.Database.type = DatabaseType.sqlite;
|
|
||||||
}
|
|
||||||
if (ActiveExperiments[Experiments.db.name] === Experiments.db.groups.betterSqlite) {
|
|
||||||
Config.Server.Database.type = DatabaseType.better_sqlite3;
|
|
||||||
}
|
|
||||||
if (this.connection == null) {
|
if (this.connection == null) {
|
||||||
const options: any = this.getDriver(Config.Server.Database);
|
const options: any = this.getDriver(Config.Server.Database);
|
||||||
// options.name = 'main';
|
// options.name = 'main';
|
||||||
@@ -62,7 +56,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]);
|
Logger.debug(LOG_TAG, 'Creating connection: ' + DatabaseType[Config.Server.Database.type], 'with:', options.type);
|
||||||
this.connection = await this.createConnection(options);
|
this.connection = await this.createConnection(options);
|
||||||
await SQLConnection.schemeSync(this.connection);
|
await SQLConnection.schemeSync(this.connection);
|
||||||
}
|
}
|
||||||
@@ -160,7 +154,7 @@ export class SQLConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static async createConnection(options: ConnectionOptions): Promise<Connection> {
|
private static async createConnection(options: ConnectionOptions): Promise<Connection> {
|
||||||
if (options.type === 'sqlite') {
|
if (options.type === 'sqlite' || options.type === 'better-sqlite3') {
|
||||||
return await createConnection(options);
|
return await createConnection(options);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -226,14 +220,22 @@ export class SQLConnection {
|
|||||||
charset: 'utf8mb4'
|
charset: 'utf8mb4'
|
||||||
};
|
};
|
||||||
} else if (config.type === DatabaseType.sqlite) {
|
} else if (config.type === DatabaseType.sqlite) {
|
||||||
|
|
||||||
|
if (ActiveExperiments[Experiments.db.name] === Experiments.db.groups.betterSqlite) {
|
||||||
|
driver = {
|
||||||
|
type: 'better-sqlite3',
|
||||||
|
database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), 'better_' + config.sqlite.DBFileName)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
driver = {
|
driver = {
|
||||||
type: 'sqlite',
|
type: 'sqlite',
|
||||||
database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), config.sqlite.DBFileName)
|
database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), config.sqlite.DBFileName)
|
||||||
};
|
};
|
||||||
|
}
|
||||||
} else if (config.type === DatabaseType.better_sqlite3) {
|
} else if (config.type === DatabaseType.better_sqlite3) {
|
||||||
driver = {
|
driver = {
|
||||||
type: 'better-sqlite3',
|
type: 'better-sqlite3',
|
||||||
database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), 'better_', config.sqlite.DBFileName)
|
database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), 'better_' + config.sqlite.DBFileName)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return driver;
|
return driver;
|
||||||
|
|||||||
Reference in New Issue
Block a user