mirror of
https://github.com/tiennm99/thptqg.git
synced 2026-10-15 16:15:21 +00:00
fix(web): read the database in chunked mode so the length can be supplied
The previous attempt passed fileLength in the inline config, and the
worker discarded it. sqlite.worker.ts builds the lazy file's config
itself and hardcodes:
fileLength: config.serverMode === "chunked"
? config.databaseLengthBytes
: undefined
So in full mode there is no way to supply a length, and the library
falls back to sizing the file with a HEAD request — which GitHub Pages
answers with the gzipped length, and then refuses to use.
Chunked mode is the only mode that takes a length. One chunk holds the
whole database, so the chunk index is always 0 and every request goes to
urlPrefix + "0"; the assembler therefore publishes <id>.sqlite30. The
length still comes from the range probe, which also checks the bytes are
a SQLite header.
dbPrefixOf and dbOf derive one form from the other and are handed to
RemoteDatabase together, so the prefix the library appends an index to
and the file the assembler writes cannot drift apart. A test pins that;
nothing else would catch it, because the symptom is a 404 per query.
The stray-artifact guard now also rejects a leftover <id>.sqlite3, which
after this change is a stale artifact rather than the published one.
sqlite-wasm-http was checked as an alternative and does not help: its
worker takes the size from a HEAD Content-Length too, and its options
expose no way to override it, so on Pages it would silently use the
compressed size. Its shared-cache backend wants COOP/COEP, but it ships
a fallback that does not, so isolation was never the blocker — the
architecture note claiming otherwise is corrected.
This commit is contained in:
1 parent
b62a352553
commit
6ab7c1f855
16 files changed
+188
-87
No files matched your search
@@ -35,10 +35,18 @@ const driverName = "sqlite"
|
||||
// even if the row count somehow passed.
|
||||
const minSizeRatio = 0.9
|
||||
|
||||
// Extension is the published suffix. Not ".db": the sql.js-httpvfs ecosystem
|
||||
// uses ".sqlite3", and keeping ".db" free lets the site assembly treat any
|
||||
// Extension is the published suffix. The trailing 0 is a chunk index, not a
|
||||
// typo: the browser reads the file through sql.js-httpvfs in chunked mode,
|
||||
// which is the only mode whose config accepts the file's length. That mode
|
||||
// builds each request's URL as urlPrefix + chunkIndex, and one chunk holds the
|
||||
// whole database, so the index is always 0 and the prefix is "<id>.sqlite3".
|
||||
//
|
||||
// The length has to come from the config because the library otherwise takes
|
||||
// it from a HEAD request, which GitHub Pages answers with the gzipped size.
|
||||
//
|
||||
// Not ".db" either: keeping that name free lets the site assembly treat any
|
||||
// stray .db or SQLite journal in the output as the leftover it is.
|
||||
const Extension = ".sqlite3"
|
||||
const Extension = ".sqlite30"
|
||||
|
||||
// Paths locates the pieces this package needs.
|
||||
type Paths struct {
|
||||
|
||||
Reference in new issue
Block a user