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

fixing linting erros. adding tslint to pretest

This commit is contained in:
Patrik J. Braun
2021-04-18 15:48:35 +02:00
parent 2223c87b9e
commit 085d7c2cd9
194 changed files with 3226 additions and 3277 deletions

View File

@@ -1,6 +1,6 @@
import {BenchmarkResult} from './BenchmarkRunner';
import {ContentWrapper} from '../src/common/entities/ConentWrapper';
import {Express} from 'express';
import {Express, NextFunction} from 'express';
import {Utils} from '../src/common/Utils';
import {Message} from '../src/common/entities/Message';
@@ -20,30 +20,30 @@ class BMExpressApp {
this.benchmark = benchmark;
}
get(match: string | string[], ...functions: ((req: any, res: any, next: Function) => void)[]) {
functions.forEach(f => {
get(match: string | string[], ...functions: ((req: any, res: any, next: NextFunction) => void)[]): void {
functions.forEach((f): void => {
this.benchmark.addAStep({
name: this.camelToSpaceSeparated(f.name),
fn: (request: any) => this.nextToPromise(f, request)
fn: (request: any): Promise<void> => this.nextToPromise(f, request)
});
});
}
private camelToSpaceSeparated(text: string) {
private camelToSpaceSeparated(text: string): string {
const result = (text.replace(/([A-Z])/g, ' $1')).toLocaleLowerCase();
return result.charAt(0).toUpperCase() + result.slice(1);
}
private nextToPromise(fn: (req: any, res: any, next: Function) => void, request: any) {
return new Promise<void>((resolve, reject) => {
private nextToPromise(fn: (req: any, res: any, next: NextFunction) => void, request: any): Promise<void> {
return new Promise<void>((resolve, reject): void => {
const response = {
header: () => {
header: (): void => {
},
json: (data: any) => {
json: (data: any): void => {
resolve(data);
}
};
fn(request, response, (err?: any) => {
fn(request, response, (err?: any): void => {
if (err) {
return reject(err);
}
@@ -76,7 +76,7 @@ export class Benchmark {
}
get BmExpressApp(): Express {
return (<unknown>this.bmExpressApp) as Express;
return (this.bmExpressApp as unknown) as Express;
}
async run(RUNS: number): Promise<BenchmarkResult> {
@@ -106,7 +106,7 @@ export class Benchmark {
const ret = this.outputToBMResult(this.name, scanned[scanned.length - 1]);
ret.duration = duration;
ret.subBenchmarks = scanned.map((o, i) => {
ret.subBenchmarks = scanned.map((o, i): BenchmarkResult => {
const stepBm = this.outputToBMResult(this.steps[i].name, o);
stepBm.duration = stepTimer[i] / RUNS;
return stepBm;
@@ -120,7 +120,7 @@ export class Benchmark {
if (output) {
if (Array.isArray(output)) {
return {
name: name,
name,
duration: null,
items: output.length,
};
@@ -128,7 +128,7 @@ export class Benchmark {
if (output instanceof ContentWrapper) {
return {
name: name,
name,
duration: null,
contentWrapper: output
};
@@ -137,7 +137,7 @@ export class Benchmark {
const msg = output.result;
if (Array.isArray(msg)) {
return {
name: name,
name,
duration: null,
items: msg.length,
};
@@ -145,7 +145,7 @@ export class Benchmark {
if (msg instanceof ContentWrapper) {
return {
name: name,
name,
duration: null,
contentWrapper: msg
};
@@ -154,7 +154,7 @@ export class Benchmark {
}
return {
name: name,
name,
duration: null
};
}
@@ -188,7 +188,7 @@ export class Benchmark {
return stepTimer;
}
addAStep(step: BenchmarkStep) {
addAStep(step: BenchmarkStep): void {
this.steps.push(step);
}

View File

@@ -6,7 +6,7 @@ import * as path from 'path';
import * as fs from 'fs';
import {Utils} from '../src/common/Utils';
import {DirectoryDTO} from '../src/common/entities/DirectoryDTO';
import {ServerConfig} from '../src/common/config/private/PrivateConfig';
import {DatabaseType, ReIndexingSensitivity} from '../src/common/config/private/PrivateConfig';
import {ProjectPath} from '../src/backend/ProjectPath';
import {Benchmark} from './Benchmark';
import {IndexingJob} from '../src/backend/model/jobs/jobs/IndexingJob';
@@ -40,21 +40,21 @@ export class BMIndexingManager extends IndexingManager {
class BMGalleryRouter extends GalleryRouter {
public static addDirectoryList(app: Express) {
public static addDirectoryList(app: Express): void {
GalleryRouter.addDirectoryList(app);
}
public static addSearch(app: Express) {
public static addSearch(app: Express): void {
GalleryRouter.addSearch(app);
}
public static addAutoComplete(app: Express) {
public static addAutoComplete(app: Express): void {
GalleryRouter.addAutoComplete(app);
}
}
class BMPersonRouter extends PersonRouter {
public static addGetPersons(app: Express) {
public static addGetPersons(app: Express): void {
PersonRouter.addGetPersons(app);
}
}
@@ -77,10 +77,10 @@ export class BenchmarkRunner {
await this.init();
await this.resetDB();
const dir = await DiskMangerWorker.scanDirectory(this.biggestDirPath);
const bm = new Benchmark('Saving directory to DB', null, () => this.resetDB());
const bm = new Benchmark('Saving directory to DB', null, (): Promise<void> => this.resetDB());
bm.addAStep({
name: 'Saving directory to DB',
fn: () => {
fn: (): Promise<void> => {
const im = new BMIndexingManager();
return im.saveToDB(dir);
}
@@ -93,19 +93,19 @@ export class BenchmarkRunner {
const bm = new Benchmark('Scanning directory');
bm.addAStep({
name: 'Scanning directory',
fn: async () => new ContentWrapper(await DiskMangerWorker.scanDirectory(this.biggestDirPath))
fn: async (): Promise<ContentWrapper> => new ContentWrapper(await DiskMangerWorker.scanDirectory(this.biggestDirPath))
});
return await bm.run(this.RUNS);
}
async bmListDirectory(): Promise<BenchmarkResult> {
Config.Server.Indexing.reIndexingSensitivity = ServerConfig.ReIndexingSensitivity.low;
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 () => {
async (): Promise<void> => {
await ObjectManagers.reset();
await ObjectManagers.InitSQLManagers();
});
@@ -115,8 +115,8 @@ export class BenchmarkRunner {
async bmListPersons(): Promise<BenchmarkResult> {
await this.setupDB();
Config.Server.Indexing.reIndexingSensitivity = ServerConfig.ReIndexingSensitivity.low;
const bm = new Benchmark('Listing Faces', Utils.clone(this.requestTemplate), async () => {
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();
});
@@ -126,16 +126,16 @@ export class BenchmarkRunner {
async bmAllSearch(text: string): Promise<{ result: BenchmarkResult, searchType: SearchQueryTypes }[]> {
await this.setupDB();
const types = Utils.enumToArray(SearchQueryTypes).map(a => a.key).concat([null]);
const types = Utils.enumToArray(SearchQueryTypes).map((a): number => a.key).concat([null]);
const results: { result: BenchmarkResult, searchType: SearchQueryTypes }[] = [];
for (let i = 0; i < types.length; i++) {
for (const type of types) {
const req = Utils.clone(this.requestTemplate);
req.query[QueryParams.gallery.search.query] = <TextSearch>{type: types[i], text: text};
const bm = new Benchmark('Searching for `' + text + '` as `' + (types[i] ? SearchQueryTypes[types[i]] : 'any') + '`', req);
req.query[QueryParams.gallery.search.query] = ({type, text} as TextSearch);
const bm = new Benchmark('Searching for `' + text + '` as `' + (type ? SearchQueryTypes[type] : 'any') + '`', req);
BMGalleryRouter.addSearch(bm.BmExpressApp);
results.push({result: await bm.run(this.RUNS), searchType: types[i]});
results.push({result: await bm.run(this.RUNS), searchType: type});
}
return results;
}
@@ -150,7 +150,7 @@ export class BenchmarkRunner {
return await bm.run(this.RUNS);
}
async getStatistic() {
async getStatistic(): Promise<string> {
await this.setupDB();
const gm = new GalleryManager();
const pm = new PersonManager();
@@ -165,7 +165,7 @@ export class BenchmarkRunner {
}
private async init() {
private async init(): Promise<string> {
if (this.inited === false) {
await this.setupDB();
@@ -176,7 +176,7 @@ export class BenchmarkRunner {
while (queue.length > 0) {
const dirPath = queue.shift();
const dir = await gm.listDirectory(dirPath);
dir.directories.forEach(d => queue.push(path.join(d.path + d.name)));
dir.directories.forEach((d): number => queue.push(path.join(d.path + d.name)));
if (biggest < dir.media.length) {
biggestPath = path.join(dir.path + dir.name);
biggest = dir.media.length;
@@ -191,11 +191,11 @@ export class BenchmarkRunner {
}
private resetDB = async () => {
private resetDB = async (): Promise<void> => {
Config.Server.Threading.enabled = false;
await ObjectManagers.reset();
await fs.promises.rmdir(ProjectPath.DBFolder, {recursive: true});
Config.Server.Database.type = ServerConfig.DatabaseType.sqlite;
Config.Server.Database.type = DatabaseType.sqlite;
Config.Server.Jobs.scheduled = [];
await ObjectManagers.InitSQLManagers();
};
@@ -203,16 +203,16 @@ export class BenchmarkRunner {
private async setupDB(): Promise<void> {
Config.Server.Threading.enabled = false;
await this.resetDB();
await new Promise<void>((resolve, reject) => {
await new Promise<void>((resolve, reject): void => {
try {
const indexingJob = new IndexingJob();
indexingJob.JobListener = {
onJobFinished: (job: IJob<any>, state: JobProgressStates, soloRun: boolean) => {
onJobFinished: (job: IJob<any>, state: JobProgressStates, soloRun: boolean): void => {
resolve();
},
onProgressUpdate: (progress: JobProgress) => {
onProgressUpdate: (progress: JobProgress): void => {
}
};
indexingJob.start().catch(console.error);

View File

@@ -51,8 +51,8 @@ const printResult = (result: BenchmarkResult, isSubResult = false) => {
printLine('| **' + result.name + '** | | **' + (result.duration).toFixed(1) + ' ms** | **' + details + '** |');
}
if (result.subBenchmarks && result.subBenchmarks.length > 1) {
for (let i = 0; i < result.subBenchmarks.length; i++) {
printResult(result.subBenchmarks[i], true);
for (const item of result.subBenchmarks) {
printResult(item, true);
}
}
};