File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
packages/sqlite_async/lib/src/web Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -63,10 +63,19 @@ class DefaultSqliteOpenFactory
6363 final workers = await _initialized;
6464 final connection = await connectToWorker (workers, path);
6565
66- // When the database is accessed through a shared worker, we implement
67- // mutexes over custom messages sent through the shared worker. In other
68- // cases, we need to implement a mutex locally.
69- final mutex = connection.access == AccessMode .throughSharedWorker
66+ // When the database is hosted in a shared worker, we don't need a local
67+ // mutex since that worker will hand out leases for us.
68+ // Additionally, package:sqlite3_web uses navigator locks internally for
69+ // OPFS databases.
70+ // Technically, the only other implementation (IndexedDB in a local context
71+ // or a dedicated worker) is inherently unsafe to use across tabs. But
72+ // wrapping those in a mutex and flushing the file system helps a little bit
73+ // (still something we're trying to avoid).
74+ final hasSqliteWebMutex =
75+ connection.access == AccessMode .throughSharedWorker ||
76+ connection.storage == StorageMode .opfs;
77+
78+ final mutex = hasSqliteWebMutex
7079 ? null
7180 : MutexImpl (identifier: path); // Use the DB path as a mutex identifier
7281
You can’t perform that action at this time.
0 commit comments