erase method
Implementation
@override
Future<void> erase(DVPrivacySubjectRef ref) async {
final DVRecordTable table = store.table;
final DVDatabaseAdapter db = table.database;
final Set<String> keys = <String>{};
for (final DVRecord row in await table.all(withDeleted: true)) {
if (!_belongs(row.key, row.values, ref.id)) continue;
final ({DVRecord row, bool gone})? removed = await _writeAtVersion(
table,
row,
write: (DVRecord at) => _deleteAt(db, table, at),
belongs: (DVRecord now) => _belongs(now.key, now.values, ref.id),
);
// Moved to someone else since it was read: theirs, and so are the
// server copy and queued writes its key would otherwise match.
if (removed == null) continue;
keys.add(jsonEncode(row.key));
await _forgetRow(db, table, removed.row);
}
// A server copy or a queued write can outlive the local row it came from,
// so each is matched on its own values, not only on a local row's key.
for (final Map<String, Object?> s in await db.query(
'SELECT * FROM ${store.serverTable}',
)) {
final String key = '${s['record_key']}';
if (keys.contains(key) ||
_belongs(_decode(key), _map(_decode(s['payload'])), ref.id)) {
await db.execute(
'DELETE FROM ${store.serverTable} WHERE record_key = ?',
<Object?>[key],
);
}
}
for (final Map<String, Object?> m in await db.query(
'SELECT * FROM ${store.logTable}',
)) {
final String key = '${m['record_key']}';
final Map<String, Object?> values = _map(
_map(_decode(m['payload']))['values'],
);
if (keys.contains(key) || _belongs(_decode(key), values, ref.id)) {
await db.execute(
'DELETE FROM ${store.logTable} WHERE mutation_id = ?',
<Object?>[m['mutation_id']],
);
}
}
}