@@ -111,9 +111,17 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
111
111
112
112
}
113
113
while let eventsToSend: [ EventForDispatch ] = self . dataStore. getFirstItems ( count: self . batchSize) {
114
+ let actualEventsSize = eventsToSend. count
114
115
var eventToSend = eventsToSend. batch ( )
115
116
if let _ = eventToSend {
116
117
// we merged the event and ready for batch
118
+ // if the bacth size is not equal to the actual event size,
119
+ // then setup the batchSizeHolder to be the size of the event.
120
+ if actualEventsSize != self . batchSize {
121
+ batchSizeHolder = actualEventsSize
122
+ self . batchSize = actualEventsSize
123
+ sendCount = actualEventsSize - 1
124
+ }
117
125
}
118
126
else {
119
127
failedBatch ( )
@@ -145,7 +153,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
145
153
failureCount += 1
146
154
case . success( _) :
147
155
// we succeeded. remove the batch size sent.
148
- if let removedItem: [ EventForDispatch ] = self . dataStore. removeFirstItems ( count: self . batchSize ) {
156
+ if let removedItem: [ EventForDispatch ] = self . dataStore. removeFirstItems ( count: failureCount > 0 ? 1 : actualEventsSize ) {
149
157
if self . batchSize == 1 && removedItem. first != event {
150
158
self . logger? . e ( " Removed event different from sent event " )
151
159
}
@@ -181,7 +189,7 @@ open class DefaultEventDispatcher : BackgroundingCallbacks, OPTEventDispatcher {
181
189
182
190
}
183
191
184
- func sendEvent( event: EventForDispatch , completionHandler: @escaping DispatchCompletionHandler ) {
192
+ open func sendEvent( event: EventForDispatch , completionHandler: @escaping DispatchCompletionHandler ) {
185
193
let config = URLSessionConfiguration . ephemeral
186
194
let session = URLSession ( configuration: config)
187
195
var request = URLRequest ( url: event. url)
0 commit comments