File tree 2 files changed +16
-4
lines changed 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -34,14 +34,14 @@ class EventBuffer {
34
34
/// Adds a raw event hash to the buffer
35
35
Future <void > add (Event event) async {
36
36
if (length >= config.maxStoredEvents) {
37
- print ('Max stored events reached. Discarding event. ' );
38
- return ;
37
+ print ('Max stored events reached. Drop first event' );
38
+ await store. drop ( 1 ) ;
39
39
}
40
40
41
41
event.timestamp = TimeUtils ().currentTime ();
42
42
await store.add (event);
43
43
44
- if (length >= config.bufferSize && numEvents == null ) {
44
+ if (length >= config.bufferSize) {
45
45
await flush ();
46
46
}
47
47
}
@@ -92,6 +92,8 @@ class EventBuffer {
92
92
93
93
Future <void > _deleteEvents (List <int > eventIds) async {
94
94
await store.delete (eventIds);
95
- numEvents = null ;
95
+ if (numEvents >= length) {
96
+ numEvents = null ;
97
+ }
96
98
}
97
99
}
Original file line number Diff line number Diff line change @@ -50,6 +50,16 @@ class Store {
50
50
return _count (db);
51
51
}
52
52
53
+ Future <void > drop (int count) async {
54
+ final db = await _getDb ();
55
+ if (db == null ) {
56
+ return ;
57
+ }
58
+ final resultCount = await db.rawDelete (
59
+ 'DELETE FROM $EVENTS_TABLE WHERE $COL_ID IN (SELECT T2.$COL_ID FROM $EVENTS_TABLE T2 ORDER BY T2.$COL_ID LIMIT $count )' );
60
+ length -= resultCount;
61
+ }
62
+
53
63
Future <void > delete (List <int > eventIds) async {
54
64
final db = await _getDb ();
55
65
if (db == null ) {
You can’t perform that action at this time.
0 commit comments