Merge pull request #1671 from famedly/krille/fix-delete-in-transactions
fix: Delete in transaction on new store does not clear cache correctly
This commit is contained in:
commit
dd31ede2a1
|
|
@ -166,7 +166,10 @@ class Box<V> {
|
|||
txn ??= boxCollection._db.transaction(name, 'readwrite');
|
||||
final store = txn.objectStore(name);
|
||||
await store.delete(key);
|
||||
_cache.remove(key);
|
||||
|
||||
// Set to null instead remove() so that inside of transactions null is
|
||||
// returned.
|
||||
_cache[key] = null;
|
||||
_cachedKeys?.remove(key);
|
||||
return;
|
||||
}
|
||||
|
|
@ -183,7 +186,7 @@ class Box<V> {
|
|||
final store = txn.objectStore(name);
|
||||
for (final key in keys) {
|
||||
await store.delete(key);
|
||||
_cache.remove(key);
|
||||
_cache[key] = null;
|
||||
_cachedKeys?.remove(key);
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -302,7 +302,9 @@ class Box<V> {
|
|||
txn.delete(name, where: 'k = ?', whereArgs: [key]);
|
||||
}
|
||||
|
||||
_cache.remove(key);
|
||||
// Set to null instead remove() so that inside of transactions null is
|
||||
// returned.
|
||||
_cache[key] = null;
|
||||
_cachedKeys?.remove(key);
|
||||
return;
|
||||
}
|
||||
|
|
@ -326,7 +328,7 @@ class Box<V> {
|
|||
}
|
||||
|
||||
for (final key in keys) {
|
||||
_cache.remove(key);
|
||||
_cache[key] = null;
|
||||
_cachedKeys?.removeAll(keys);
|
||||
}
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,18 @@ void main() {
|
|||
await box.clear();
|
||||
});
|
||||
|
||||
test('Box.delete in transaction', () async {
|
||||
final box = collection.openBox<Map>('cats');
|
||||
await box.put('fluffy', data);
|
||||
await box.put('loki', data2);
|
||||
await collection.transaction(() async {
|
||||
await box.delete('fluffy');
|
||||
expect(await box.get('fluffy'), null);
|
||||
});
|
||||
expect(await box.get('fluffy'), null);
|
||||
await box.clear();
|
||||
});
|
||||
|
||||
test('Box.deleteAll', () async {
|
||||
final box = collection.openBox<Map>('cats');
|
||||
await box.put('fluffy', data);
|
||||
|
|
|
|||
Loading…
Reference in New Issue