Skip to content

Commit 46452c9

Browse files
committed
Fix indexDB putObject concurrency issue and cache.
1 parent c14e052 commit 46452c9

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

packages-exp/auth-exp/src/platform_browser/persistence/indexed_db.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,11 @@ export async function _putObject(
127127
key: string,
128128
value: PersistenceValue | string
129129
): Promise<void> {
130-
const getRequest = getObjectStore(db, false).get(key);
131-
const data = await new DBPromise<DBObject | null>(getRequest).toPromise();
132-
if (data) {
133-
// Force an index signature on the user object
134-
data.value = value as PersistedBlob;
135-
const request = getObjectStore(db, true).put(data);
136-
return new DBPromise<void>(request).toPromise();
137-
} else {
138-
const request = getObjectStore(db, true).add({
139-
[DB_DATA_KEYPATH]: key,
140-
value
141-
});
142-
return new DBPromise<void>(request).toPromise();
143-
}
130+
const request = getObjectStore(db, true).put({
131+
[DB_DATA_KEYPATH]: key,
132+
value
133+
});
134+
return new DBPromise<void>(request).toPromise();
144135
}
145136

146137
async function getObject(
@@ -395,9 +386,6 @@ class IndexedDBLocalPersistence implements InternalPersistence {
395386
key: string,
396387
newValue: PersistenceValue | null
397388
): void {
398-
if (!this.listeners[key]) {
399-
return;
400-
}
401389
this.localCache[key] = newValue;
402390
for (const listener of Array.from(this.listeners[key])) {
403391
listener(newValue);
@@ -434,7 +422,6 @@ class IndexedDBLocalPersistence implements InternalPersistence {
434422

435423
if (this.listeners[key].size === 0) {
436424
delete this.listeners[key];
437-
delete this.localCache[key];
438425
}
439426
}
440427

packages-exp/auth-exp/src/platform_browser/persistence/local_storage.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ class BrowserLocalPersistence
165165
}
166166

167167
private notifyListeners(key: string, value: string | null): void {
168-
if (!this.listeners[key]) {
169-
return;
170-
}
171168
this.localCache[key] = value;
172169
for (const listener of Array.from(this.listeners[key])) {
173170
listener(value ? JSON.parse(value) : value);
@@ -209,7 +206,6 @@ class BrowserLocalPersistence
209206
}
210207

211208
_addListener(key: string, listener: StorageEventListener): void {
212-
this.localCache[key] = this.storage.getItem(key);
213209
if (Object.keys(this.listeners).length === 0) {
214210
// Whether browser can detect storage event when it had already been pushed to the background.
215211
// This may happen in some mobile browsers. A localStorage change in the foreground window
@@ -231,7 +227,6 @@ class BrowserLocalPersistence
231227

232228
if (this.listeners[key].size === 0) {
233229
delete this.listeners[key];
234-
delete this.localCache[key];
235230
}
236231
}
237232

0 commit comments

Comments
 (0)