Skip to content

Commit

Permalink
Add limit for storing events
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKaN committed Oct 26, 2023
1 parent 7007742 commit e7f4897
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Piano Analytics SDK for Android

## v3.3.4-SNAPSHOT
* Added limit for event storage
* Updated dependencies:
- com.squareup.okhttp3:okhttp [4.11.0 -> 4.12.0]
https://square.github.io/okhttp/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ internal class EventRepository(
)
}

fun deleteOutOfLimitNotSentEvents(limit: Int) {
databaseHelper.delete(
"${EventRecord.IS_SENT} = 0 AND ${EventRecord.ID} <= (" +
"SELECT ${EventRecord.ID} FROM ${EventRecord.TABLE_NAME} WHERE ${EventRecord.IS_SENT} = 0 " +
"ORDER by ${EventRecord.ID} DESC LIMIT 1 OFFSET ?)",
limit.toString()
)
}

fun getNotSentEvents(): List<EventRecord> = databaseHelper.query(
selection = "${EventRecord.IS_SENT} = 0",
orderBy = "${EventRecord.TIME} ASC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal class SendTask(
) : Runnable {
override fun run() {
eventRepository.deleteOldEvents(configuration.eventsOfflineStorageLifetime)
eventRepository.deleteOutOfLimitNotSentEvents(EVENTS_LIMIT)
if (deviceInfoProvider.connectionType == ConnectionType.OFFLINE) {
Timber.w("Can't send events - no connection")
return
Expand Down Expand Up @@ -61,5 +62,6 @@ internal class SendTask(
companion object {
internal val MEDIA_TYPE by lazy(LazyThreadSafetyMode.NONE) { "application/json; charset=UTF-8".toMediaType() }
private const val CHUNK_SIZE = 50
private const val EVENTS_LIMIT = 2000
}
}

0 comments on commit e7f4897

Please sign in to comment.