diff --git a/.gitignore b/.gitignore index 5c15d81..fc5c447 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ yt_auth_token spotify_auth_token tidal_auth_token *.db +*.db-shm +*.db-wal feed.xml playbook.yml inventory.yml diff --git a/package-lock.json b/package-lock.json index c4b837d..c8efb68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "prettier": "^3.1.0", "prettier-plugin-svelte": "^3.2.6", "svelte": "^5", + "svelte-adapter-bun": "^0.5.2", "svelte-check": "^4.0.0", "tslib": "^2.0.0", "typescript": "^5.0.0" @@ -3309,6 +3310,20 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globalyzer": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/globalyzer/-/globalyzer-0.1.0.tgz", + "integrity": "sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/globrex": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/globrex/-/globrex-0.1.2.tgz", + "integrity": "sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==", + "dev": true, + "license": "MIT" + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -5124,6 +5139,16 @@ "node": ">=18" } }, + "node_modules/svelte-adapter-bun": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/svelte-adapter-bun/-/svelte-adapter-bun-0.5.2.tgz", + "integrity": "sha512-xEtFgaal6UgrCwwkSIcapO9kopoFNUYCYqyKCikdqxX9bz2TDYnrWQZ7qBnkunMxi1HOIERUCvTcebYGiarZLA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tiny-glob": "^0.2.9" + } + }, "node_modules/svelte-check": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/svelte-check/-/svelte-check-4.3.0.tgz", @@ -5260,6 +5285,17 @@ "node": ">=8" } }, + "node_modules/tiny-glob": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", + "integrity": "sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==", + "dev": true, + "license": "MIT", + "dependencies": { + "globalyzer": "0.1.0", + "globrex": "^0.1.2" + } + }, "node_modules/tinyglobby": { "version": "0.2.14", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz", diff --git a/package.json b/package.json index 4e6b8c5..47ce045 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "prettier": "^3.1.0", "prettier-plugin-svelte": "^3.2.6", "svelte": "^5", + "svelte-adapter-bun": "^0.5.2", "svelte-check": "^4.0.0", "tslib": "^2.0.0", "typescript": "^5.0.0" diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index 454a83a..933149e 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -97,6 +97,7 @@ const ignoredUsers: string[] = let databaseReady = false; if (enableVerboseLog) { + logger.verbose('Enabling verbose DB log'); sqlite3.verbose(); db.on('change', (t, d, table, rowid) => { logger.verbose('DB change event', t, d, table, rowid); @@ -106,8 +107,16 @@ if (enableVerboseLog) { logger.verbose('Running', sql); }); - db.on('profile', (sql) => { - logger.verbose('Finished', sql); + db.on('profile', (sql, time) => { + if (sql.startsWith('EXPLAIN')) { + return; + } + logger.verbose('Finished', sql, 'time', time); + if (sql.startsWith('SELECT')) { + db.get('EXPLAIN QUERY PLAN ' + sql, (a: sqlite3.RunResult, b: Error) => { + logger.verbose(sql, a, b); + }); + } }); } @@ -153,6 +162,9 @@ async function applyMigration(migration: Migration) { db.on('open', () => { logger.info('Opened database'); db.serialize(); + db.run('pragma journal_mode = WAL;'); + db.run('pragma synchronous = normal;'); + db.run('pragma journal_size_limit = 6144000;'); db.run('CREATE TABLE IF NOT EXISTS "migrations" ("id" integer,"name" TEXT, PRIMARY KEY (id))'); db.all('SELECT id FROM migrations', (err, rows: Migration[]) => { if (err !== null) { @@ -344,6 +356,26 @@ function getMigrations(): Migration[] { name: 'song tidal id', statement: ` ALTER TABLE songs ADD COLUMN tidalId TEXT NULL;` + }, + { + id: 10, + name: 'add indexes', + statement: ` + CREATE INDEX posts_created_at ON posts(created_at); + CREATE INDEX accounts_acct ON accounts(acct); + CREATE INDEX accounts_username ON accounts(username);` + }, + { + id: 11, + name: 'add FK indexes', + statement: ` + CREATE INDEX migrations_id ON migrations(id); + CREATE INDEX accountsavatars_account_url ON accountsavatars(account_url); + CREATE INDEX posts_account_id ON posts(account_id); + CREATE INDEX poststags_post_id ON poststags(post_id); + CREATE INDEX poststags_tag_url ON poststags(tag_url); + CREATE INDEX songs_post_url ON songs(post_url); + CREATE INDEX songsthumbnails_song_thumbnailUrl ON songsthumbnails(song_thumbnailUrl);` } ]; } @@ -618,7 +650,6 @@ function getSongData(postIdsParams: string, postIds: string[]): Promise { - const start = performance.now(); const p = await fetch('/'); - const afterFetch = performance.now(); - console.debug('+page.ts: Fetch took', afterFetch - start, 'ms'); setHeaders({ 'cache-control': 'public,max-age=60' }); - const afterHeaders = performance.now(); - console.debug('+page.ts: Headers took', afterHeaders - afterFetch, 'ms'); const j: Post[] = await p.json(); - const afterJson = performance.now(); - console.debug('+page.ts: JSON took', afterJson - afterHeaders, 'ms'); return { posts: j }; diff --git a/svelte.config.js b/svelte.config.js index 2f89ba0..d986721 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,3 +1,5 @@ +// Does not seem to work +//import adapter from 'svelte-adapter-bun'; import adapter from '@sveltejs/adapter-node'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';