removeEvents method
Future<void>
removeEvents({
- List<
String> ? ids, - List<
String> ? pubKeys, - List<
int> ? kinds, - Map<
String, List< ? tags,String> > - int? since,
- int? until,
override
Remove events from cache with flexible filtering
ids - list of event ids
pubKeys - list of authors pubKeys
kinds - list of kinds
tags - map of tags (e.g. {'p': 'pubkey1', 'e': 'eventid1'})
since - timestamp
until - timestamp
If all parameters are empty, returns early (doesn't delete everything)
Implementation
@override
Future<void> removeEvents({
List<String>? ids,
List<String>? pubKeys,
List<int>? kinds,
Map<String, List<String>>? tags,
int? since,
int? until,
}) async {
await dbRdy;
// If all parameters are empty, return early (don't delete everything)
if ((ids == null || ids.isEmpty) &&
(pubKeys == null || pubKeys.isEmpty) &&
(kinds == null || kinds.isEmpty) &&
(tags == null || tags.isEmpty) &&
since == null &&
until == null) {
return;
}
final eventBox = _objectBox.store.box<DbNip01Event>();
// Build conditions list
final conditions = <Condition<DbNip01Event>>[];
if (ids != null && ids.isNotEmpty) {
conditions.add(DbNip01Event_.nostrId.oneOf(ids));
}
if (pubKeys != null && pubKeys.isNotEmpty) {
conditions.add(DbNip01Event_.pubKey.oneOf(pubKeys));
}
if (kinds != null && kinds.isNotEmpty) {
conditions.add(DbNip01Event_.kind.oneOf(kinds));
}
if (since != null) {
conditions.add(DbNip01Event_.createdAt.greaterOrEqual(since));
}
if (until != null) {
conditions.add(DbNip01Event_.createdAt.lessOrEqual(until));
}
if (tags != null && tags.isNotEmpty) {
final matchingEventIds = _findEventIdsByTags(eventBox, tags);
if (matchingEventIds.isEmpty) {
return;
}
conditions.add(DbNip01Event_.dbId.oneOf(matchingEventIds.toList()));
}
// Build and execute the query
final query = conditions.isEmpty
? eventBox.query().build()
: eventBox.query(conditions.reduce((a, b) => a.and(b))).build();
final results = query.find();
// Remove matching events
eventBox.removeMany(results.map((e) => e.dbId).toList());
}