1
1
import type { Database } from '@sqlite.org/sqlite-wasm'
2
2
import type { DatabaseAdapter , DatabaseBindParams } from '@nuxt/content'
3
- import { measurePerformance } from './performance'
4
3
import { decompressSQLDump } from './dump'
5
4
import { parseJsonFields } from './collection'
6
5
import { fetchDatabase } from './api'
@@ -36,12 +35,9 @@ export function loadDatabaseAdapter<T>(collection: T): DatabaseAdapter {
36
35
}
37
36
38
37
async function loadAdapter < T > ( collection : T ) {
39
- const perf = measurePerformance ( )
40
38
if ( ! db ) {
41
39
const sqlite3InitModule = await import ( '@sqlite.org/sqlite-wasm' ) . then ( m => m . default )
42
40
const sqlite3 = await sqlite3InitModule ( )
43
- perf . tick ( 'Import SQLite Module' )
44
-
45
41
db = new sqlite3 . oo1 . DB ( )
46
42
}
47
43
@@ -75,10 +71,8 @@ async function loadAdapter<T>(collection: T) {
75
71
}
76
72
}
77
73
78
- perf . tick ( 'Get Local Cache' )
79
74
if ( ! compressedDump ) {
80
75
compressedDump = await fetchDatabase ( undefined , String ( collection ) )
81
- perf . tick ( 'Download Database' )
82
76
if ( ! import . meta. dev ) {
83
77
try {
84
78
window . localStorage . setItem ( `content_${ checksumId } ` , checksums [ String ( collection ) ] )
@@ -87,12 +81,10 @@ async function loadAdapter<T>(collection: T) {
87
81
catch ( error ) {
88
82
console . error ( 'Database integrity check failed, rebuilding database' , error )
89
83
}
90
- perf . tick ( 'Store Database' )
91
84
}
92
85
}
93
86
94
87
const dump = await decompressSQLDump ( compressedDump ! )
95
- perf . tick ( 'Decompress Database' )
96
88
97
89
await db . exec ( { sql : `DROP TABLE IF EXISTS ${ tables [ String ( collection ) ] } ` } )
98
90
if ( checksumState === 'mismatch' ) {
@@ -107,10 +99,7 @@ async function loadAdapter<T>(collection: T) {
107
99
console . error ( 'Error executing command' , error )
108
100
}
109
101
}
110
- perf . tick ( 'Restore Dump' )
111
102
}
112
103
113
- perf . end ( 'Database Loaded' )
114
-
115
104
return db
116
105
}
0 commit comments