Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3387000
D9108.id30911.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9108.id30911.diff
View Options
diff --git a/web/database/database-module-provider.js b/web/database/database-module-provider.js
--- a/web/database/database-module-provider.js
+++ b/web/database/database-module-provider.js
@@ -36,23 +36,38 @@
worker: SharedWorker;
workerProxy: WorkerConnectionProxy;
initPromise: Promise<void>;
- status: DatabaseStatus;
+ status: DatabaseStatus = databaseStatuses.notSupported;
- constructor() {
- const currentLoggedInUserID = preloadedState.currentUserInfo?.anonymous
- ? undefined
- : preloadedState.currentUserInfo?.id;
- const isSupported = isSQLiteSupported(currentLoggedInUserID);
+ async init(currentLoggedInUserID: ?string): Promise<void> {
+ if (!currentLoggedInUserID) {
+ return;
+ }
- if (!isSupported || isDesktopSafari) {
+ if (!isSQLiteSupported(currentLoggedInUserID)) {
+ console.warn('Sqlite is not supported');
this.status = databaseStatuses.notSupported;
- } else {
- this.init();
+ return;
+ }
+
+ if (this.status === databaseStatuses.initInProgress) {
+ await this.initPromise;
+ return;
+ }
+
+ if (
+ status === databaseStatuses.initSuccess ||
+ status === databaseStatuses.initError
+ ) {
+ return;
}
- }
- init(encryptionKey?: ?SubtleCrypto$JsonWebKey) {
this.status = databaseStatuses.initInProgress;
+
+ let encryptionKey = null;
+ if (isDesktopSafari) {
+ encryptionKey = await getSafariEncryptionKey();
+ }
+
this.worker = new SharedWorker(DATABASE_WORKER_PATH);
this.worker.onerror = console.error;
this.workerProxy = new WorkerConnectionProxy(
@@ -77,24 +92,8 @@
console.error(`Database initialization failure`, error);
}
})();
- }
-
- async initDBForLoggedInUser(currentLoggedInUserID: ?string) {
- if (this.status === databaseStatuses.initSuccess) {
- return;
- }
- if (
- this.status === databaseStatuses.notSupported &&
- isSQLiteSupported(currentLoggedInUserID)
- ) {
- let encryptionKey = null;
- if (isDesktopSafari) {
- encryptionKey = await getSafariEncryptionKey();
- }
-
- this.init(encryptionKey);
- }
+ await this.initPromise;
}
async clearSensitiveData(): Promise<void> {
@@ -146,6 +145,10 @@
async function getDatabaseModule(): Promise<DatabaseModule> {
if (!databaseModule) {
databaseModule = new DatabaseModule();
+ const currentLoggedInUserID = preloadedState.currentUserInfo?.anonymous
+ ? undefined
+ : preloadedState.currentUserInfo?.id;
+ await databaseModule.init(currentLoggedInUserID);
}
return databaseModule;
}
diff --git a/web/database/sqlite-data-handler.js b/web/database/sqlite-data-handler.js
--- a/web/database/sqlite-data-handler.js
+++ b/web/database/sqlite-data-handler.js
@@ -50,7 +50,7 @@
const databaseModule = await getDatabaseModule();
if (currentLoggedInUserID) {
- await databaseModule.initDBForLoggedInUser(currentLoggedInUserID);
+ await databaseModule.init(currentLoggedInUserID);
}
if (!rehydrateConcluded) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 7:11 AM (21 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2600065
Default Alt Text
D9108.id30911.diff (3 KB)
Attached To
Mode
D9108: [web] Initialize database at startup on safari
Attached
Detach File
Event Timeline
Log In to Comment