Skip to content

Commit 734877c

Browse files
committed
fix: remove invalid session records
1 parent 108a15c commit 734877c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/session/internal/outcomes/impl/OutcomeEventsRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.onesignal.session.internal.influence.Influence
88
import com.onesignal.session.internal.influence.InfluenceChannel
99
import com.onesignal.session.internal.influence.InfluenceType
1010
import com.onesignal.session.internal.influence.InfluenceType.Companion.fromString
11-
import com.onesignal.session.internal.outcomes.migrations.RemoveZeroSessionTimeRecords
11+
import com.onesignal.session.internal.outcomes.migrations.RemoveInvalidSessionTimeRecords
1212
import kotlinx.coroutines.Dispatchers
1313
import kotlinx.coroutines.withContext
1414
import org.json.JSONArray
@@ -102,7 +102,7 @@ internal class OutcomeEventsRepository(
102102
override suspend fun getAllEventsToSend(): List<OutcomeEventParams> {
103103
val events: MutableList<OutcomeEventParams> = ArrayList()
104104
withContext(Dispatchers.IO) {
105-
RemoveZeroSessionTimeRecords.run(_databaseProvider)
105+
RemoveInvalidSessionTimeRecords.run(_databaseProvider)
106106
_databaseProvider.os.query(OutcomeEventsTable.TABLE_NAME) { cursor ->
107107
if (cursor.moveToFirst()) {
108108
do {
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ import com.onesignal.core.internal.database.IDatabaseProvider
44
import com.onesignal.session.internal.outcomes.impl.OutcomeEventsTable
55

66
/**
7-
* Purpose: Clean up invalid cached os__session_duration outcome records
8-
* with zero session_time produced in SDK versions 5.1.15 to 5.1.20 so we stop
9-
* sending these requests to the backend.
7+
* Purpose: Clean up invalid cached os__session_duration outcome records with
8+
* 1. zero session_time produced in SDK versions 5.1.15 to 5.1.20
9+
* 2. missing session_time produced in SDK
10+
* so we stop sending these requests to the backend.
1011
*
1112
* Issue: SessionService.backgroundRun() didn't account for it being run more
1213
* than one time in the background, when this happened it would create a
13-
* outcome record with zero time which is invalid.
14+
* outcome record with zero time or null which is invalid.
1415
*/
15-
object RemoveZeroSessionTimeRecords {
16+
object RemoveInvalidSessionTimeRecords {
1617
fun run(databaseProvider: IDatabaseProvider) {
1718
databaseProvider.os.delete(
1819
OutcomeEventsTable.TABLE_NAME,
1920
OutcomeEventsTable.COLUMN_NAME_NAME + " = \"os__session_duration\"" +
20-
" AND " + OutcomeEventsTable.COLUMN_NAME_SESSION_TIME + " = 0",
21+
" AND (" + OutcomeEventsTable.COLUMN_NAME_SESSION_TIME + " = 0" +
22+
" OR " + OutcomeEventsTable.COLUMN_NAME_SESSION_TIME + " IS NULL)",
2123
null,
2224
)
2325
}

0 commit comments

Comments
 (0)