Skip to content

Commit

Permalink
migration cleaning up invalid cached outcomes
Browse files Browse the repository at this point in the history
Clean up invalid cached os__session_duration outcome records
with zero session_time produced in SDK versions 5.1.15 to 5.1.20 so we
stop sending these requests to the backend.
  • Loading branch information
jkasten2 committed Aug 28, 2024
1 parent 3d3c5f2 commit 1ab8dcc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.onesignal.session.internal.influence.Influence
import com.onesignal.session.internal.influence.InfluenceChannel
import com.onesignal.session.internal.influence.InfluenceType
import com.onesignal.session.internal.influence.InfluenceType.Companion.fromString
import com.onesignal.session.internal.outcomes.migrations.RemoveZeroSessionTimeRecords
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.json.JSONArray
Expand Down Expand Up @@ -101,6 +102,7 @@ internal class OutcomeEventsRepository(
override suspend fun getAllEventsToSend(): List<OutcomeEventParams> {
val events: MutableList<OutcomeEventParams> = ArrayList()
withContext(Dispatchers.IO) {
RemoveZeroSessionTimeRecords.run(_databaseProvider)
_databaseProvider.os.query(OutcomeEventsTable.TABLE_NAME) { cursor ->
if (cursor.moveToFirst()) {
do {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.onesignal.session.internal.outcomes.migrations

import com.onesignal.core.internal.database.IDatabaseProvider
import com.onesignal.session.internal.outcomes.impl.OutcomeEventsTable

/**
* Purpose: Clean up invalid cached os__session_duration outcome records
* with zero session_time produced in SDK versions 5.1.15 to 5.1.20 so we stop
* sending these requests to the backend.
*
* Issue: SessionService.backgroundRun() didn't account for it being run more
* than one time in the background, when this happened it would create a
* outcome record with zero time which is invalid.
*/
object RemoveZeroSessionTimeRecords {
fun run(databaseProvider: IDatabaseProvider) {
databaseProvider.os.delete(
OutcomeEventsTable.TABLE_NAME,
OutcomeEventsTable.COLUMN_NAME_NAME + " = \"os__session_duration\"" +
" AND " + OutcomeEventsTable.COLUMN_NAME_SESSION_TIME + " = 0",
null,
)
}
}

0 comments on commit 1ab8dcc

Please sign in to comment.