From 3d34b16340edd07208f2e72095d7cb9218c6cfd0 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Tue, 22 Feb 2022 14:06:52 +0100 Subject: [PATCH] Experimenting with better-sqlite3 --- benchmark/Experiments.ts | 7 +++--- benchmark/docker-compose/docker-compose.yml | 2 +- package-lock.json | 25 +++++++++++++++++++ package.json | 1 + .../model/database/sql/SQLConnection.ts | 12 +++++++++ src/common/config/private/PrivateConfig.ts | 2 +- 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/benchmark/Experiments.ts b/benchmark/Experiments.ts index fb5e9a70..89019796 100644 --- a/benchmark/Experiments.ts +++ b/benchmark/Experiments.ts @@ -1,8 +1,9 @@ export const Experiments = { - loadPhotoMetadata: { - name: 'loadPhotoMetadata', + db: { + name: 'SQlite', groups: { - exifr: 'exifr', exifrAll: 'exifrAll', exifrSelected: 'exifrSelected', exifreader: 'exifreader', exiftool: 'exiftool' + sqlite3: 'sqlite3', + betterSqlite: 'better-sqlite' } } }; diff --git a/benchmark/docker-compose/docker-compose.yml b/benchmark/docker-compose/docker-compose.yml index b39b9742..fcfaa25c 100644 --- a/benchmark/docker-compose/docker-compose.yml +++ b/benchmark/docker-compose/docker-compose.yml @@ -9,7 +9,7 @@ services: volumes: - "./pigallery2/benchmark_config:/app/data/config" # CHANGE ME - "db-benchmark-data:/app/data/db" - - "./pigallery2/images:/app/data/images" # CHANGE ME, ':ro' mean read-only + - "./pigallery2/images:/app/data/images:ro" # CHANGE ME, ':ro' mean read-only - "./pigallery2/tmp:/app/data/tmp" # CHANGE ME expose: - "80" diff --git a/package-lock.json b/package-lock.json index c423dd0b..0de6f78e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4630,6 +4630,15 @@ "integrity": "sha1-5tXqjF2tABMEpwsiY4RH9pyy+Ak=", "dev": true }, + "better-sqlite3": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-7.5.0.tgz", + "integrity": "sha512-6FdG9DoytYGDhLW7VWW1vxjEz7xHkqK6LnaUQYA8d6GHNgZhu9PFX2xwKEEnSBRoT1J4PjTUPeg217ShxNmuPg==", + "requires": { + "bindings": "^1.5.0", + "prebuild-install": "^7.0.0" + } + }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -4648,6 +4657,14 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bl": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/bl/-/bl-4.0.3.tgz", @@ -8351,6 +8368,11 @@ "resolved": "https://registry.npmjs.org/file-type/-/file-type-9.0.0.tgz", "integrity": "sha512-Qe/5NJrgIOlwijpq3B7BEpzPFcgzggOTagZmkXQY4LA6bsXKTUstK7Wp12lEJ/mLKTpvIZxmIuRcLYWT6ov9lw==" }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, "filelist": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.2.tgz", @@ -8924,6 +8946,7 @@ "dev": true, "optional": true, "requires": { + "bindings": "^1.5.0", "nan": "^2.12.1" } }, @@ -19967,6 +19990,7 @@ "dev": true, "optional": true, "requires": { + "bindings": "^1.5.0", "nan": "^2.12.1" } }, @@ -20682,6 +20706,7 @@ "dev": true, "optional": true, "requires": { + "bindings": "^1.5.0", "nan": "^2.12.1" } }, diff --git a/package.json b/package.json index 06ddbf82..fb3d88da 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "dependencies": { "archiver": "5.3.0", "bcrypt": "5.0.1", + "better-sqlite3": "^7.5.0", "cookie-parser": "1.4.6", "cookie-session": "2.0.0", "csurf": "1.11.0", diff --git a/src/backend/model/database/sql/SQLConnection.ts b/src/backend/model/database/sql/SQLConnection.ts index 825613db..a082a609 100644 --- a/src/backend/model/database/sql/SQLConnection.ts +++ b/src/backend/model/database/sql/SQLConnection.ts @@ -22,6 +22,7 @@ import {DatabaseType, ServerDataBaseConfig, SQLLogLevel} from '../../../../commo import {AlbumBaseEntity} from './enitites/album/AlbumBaseEntity'; import {SavedSearchEntity} from './enitites/album/SavedSearchEntity'; import {NotificationManager} from '../../NotifocationManager'; +import {ActiveExperiments, Experiments} from '../../../../../benchmark/Experiments'; const LOG_TAG = '[SQLConnection]'; @@ -34,6 +35,12 @@ export class SQLConnection { } public static async getConnection(): Promise { + 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) { const options: any = this.getDriver(Config.Server.Database); // options.name = 'main'; @@ -223,6 +230,11 @@ export class SQLConnection { type: 'sqlite', database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), config.sqlite.DBFileName) }; + } else if (config.type === DatabaseType.better_sqlite3) { + driver = { + type: 'better-sqlite3', + database: path.join(ProjectPath.getAbsolutePath(config.dbFolder), 'better_', config.sqlite.DBFileName) + }; } return driver; } diff --git a/src/common/config/private/PrivateConfig.ts b/src/common/config/private/PrivateConfig.ts index 3f6b6ff4..1e1915ce 100644 --- a/src/common/config/private/PrivateConfig.ts +++ b/src/common/config/private/PrivateConfig.ts @@ -10,7 +10,7 @@ import {SortingMethods} from '../../entities/SortingMethods'; import {UserRoles} from '../../entities/UserDTO'; export enum DatabaseType { - memory = 1, mysql = 2, sqlite = 3 + memory = 1, mysql = 2, sqlite = 3, better_sqlite3 } export enum LogLevel {