11import type { Database } from '@sqlite.org/sqlite-wasm'
22import type { DatabaseAdapter , DatabaseBindParams } from '@nuxt/content'
3- import { measurePerformance } from './performance'
43import { decompressSQLDump } from './dump'
54import { parseJsonFields } from './collection'
65import { fetchDatabase } from './api'
@@ -36,12 +35,9 @@ export function loadDatabaseAdapter<T>(collection: T): DatabaseAdapter {
3635}
3736
3837async function loadAdapter < T > ( collection : T ) {
39- const perf = measurePerformance ( )
4038 if ( ! db ) {
4139 const sqlite3InitModule = await import ( '@sqlite.org/sqlite-wasm' ) . then ( m => m . default )
4240 const sqlite3 = await sqlite3InitModule ( )
43- perf . tick ( 'Import SQLite Module' )
44-
4541 db = new sqlite3 . oo1 . DB ( )
4642 }
4743
@@ -75,10 +71,8 @@ async function loadAdapter<T>(collection: T) {
7571 }
7672 }
7773
78- perf . tick ( 'Get Local Cache' )
7974 if ( ! compressedDump ) {
8075 compressedDump = await fetchDatabase ( undefined , String ( collection ) )
81- perf . tick ( 'Download Database' )
8276 if ( ! import . meta. dev ) {
8377 try {
8478 window . localStorage . setItem ( `content_${ checksumId } ` , checksums [ String ( collection ) ] )
@@ -87,12 +81,10 @@ async function loadAdapter<T>(collection: T) {
8781 catch ( error ) {
8882 console . error ( 'Database integrity check failed, rebuilding database' , error )
8983 }
90- perf . tick ( 'Store Database' )
9184 }
9285 }
9386
9487 const dump = await decompressSQLDump ( compressedDump ! )
95- perf . tick ( 'Decompress Database' )
9688
9789 await db . exec ( { sql : `DROP TABLE IF EXISTS ${ tables [ String ( collection ) ] } ` } )
9890 if ( checksumState === 'mismatch' ) {
@@ -107,10 +99,7 @@ async function loadAdapter<T>(collection: T) {
10799 console . error ( 'Error executing command' , error )
108100 }
109101 }
110- perf . tick ( 'Restore Dump' )
111102 }
112103
113- perf . end ( 'Database Loaded' )
114-
115104 return db
116105}
0 commit comments