-
Notifications
You must be signed in to change notification settings - Fork 27
Remote maxReplayBufferSize #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ package io.radar.sdk.util | |||||||||||||
|
|
||||||||||||||
| import io.radar.sdk.RadarSettings | ||||||||||||||
| import io.radar.sdk.model.RadarReplay | ||||||||||||||
| import io.radar.sdk.model.RadarSdkConfiguration | ||||||||||||||
| import android.content.Context | ||||||||||||||
| import android.content.SharedPreferences | ||||||||||||||
| import androidx.core.content.edit | ||||||||||||||
|
|
@@ -24,11 +25,18 @@ internal class RadarSimpleReplayBuffer(private val context: Context) : RadarRepl | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| override fun write(replayParams: JSONObject) { | ||||||||||||||
| if (buffer.size >= MAXIMUM_CAPACITY) { | ||||||||||||||
| val sdkConfiguration = RadarSettings.getSdkConfiguration(context) | ||||||||||||||
| val maxBufferSize = if (sdkConfiguration.maxReplayBufferSize > 0) { | ||||||||||||||
| sdkConfiguration.maxReplayBufferSize | ||||||||||||||
| } else { | ||||||||||||||
| RadarSdkConfiguration.DEFAULT_MAX_REPLAY_BUFFER_SIZE | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+29
to
+33
|
||||||||||||||
| val maxBufferSize = if (sdkConfiguration.maxReplayBufferSize > 0) { | |
| sdkConfiguration.maxReplayBufferSize | |
| } else { | |
| RadarSdkConfiguration.DEFAULT_MAX_REPLAY_BUFFER_SIZE | |
| } | |
| val maxBufferSize = sdkConfiguration.maxReplayBufferSize |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from if to while is correct for ensuring the buffer size constraint is satisfied when maxBufferSize is reduced. However, when maxBufferSize is significantly smaller than the current buffer.size, this could result in removing many items in a tight loop. Consider adding a comment explaining why a while loop is necessary here, or consider clearing multiple items in a single operation if the difference is large for better performance.
| // Use a while-loop (instead of a single if) to ensure the buffer is trimmed | |
| // even when maxReplayBufferSize is reduced to a value much smaller than the | |
| // current buffer size. The loop is bounded by MAXIMUM_CAPACITY, so this | |
| // remains inexpensive in practice. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ class RadarSdkConfigurationTest { | |
| private var useForegroundLocationUpdatedAtMsDiff = false | ||
| private var locationManagerTimeout = 123456 | ||
| private var syncAfterSetUser = false | ||
| private var maxReplayBufferSize = 120 | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
|
|
@@ -51,6 +52,7 @@ class RadarSdkConfigurationTest { | |
| "useForegroundLocationUpdatedAtMsDiff":$useForegroundLocationUpdatedAtMsDiff, | ||
| "locationManagerTimeout":$locationManagerTimeout, | ||
| "syncAfterSetUser":$syncAfterSetUser, | ||
| "maxReplayBufferSize":$maxReplayBufferSize, | ||
| }""".trimIndent() | ||
| } | ||
|
|
||
|
|
@@ -72,6 +74,7 @@ class RadarSdkConfigurationTest { | |
| useForegroundLocationUpdatedAtMsDiff, | ||
| locationManagerTimeout, | ||
| syncAfterSetUser, | ||
| maxReplayBufferSize, | ||
| ).toJson().toString() | ||
| ) | ||
| } | ||
|
|
@@ -92,6 +95,7 @@ class RadarSdkConfigurationTest { | |
| assertEquals(useForegroundLocationUpdatedAtMsDiff, settings.useForegroundLocationUpdatedAtMsDiff) | ||
| assertEquals(locationManagerTimeout, settings.locationManagerTimeout) | ||
| assertEquals(syncAfterSetUser, settings.syncAfterSetUser) | ||
| assertEquals(maxReplayBufferSize, settings.maxReplayBufferSize) | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -109,6 +113,7 @@ class RadarSdkConfigurationTest { | |
| assertTrue(settings.useOpenedAppConversion) | ||
| assertFalse(settings.useForegroundLocationUpdatedAtMsDiff) | ||
| assertEquals(0, settings.locationManagerTimeout) | ||
| assertEquals(120, settings.maxReplayBufferSize) | ||
|
||
| } | ||
|
|
||
| private fun String.removeWhitespace(): String = replace("\\s".toRegex(), "") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic restricts maxReplayBufferSize to values less than or equal to DEFAULT_MAX_REPLAY_BUFFER_SIZE (120). This defeats the purpose of having a remotely configurable buffer size, as the server cannot increase the buffer size beyond 120. If the intention is to allow remote configuration to adjust the buffer size, consider either removing the upper bound check or documenting why 120 is a hard limit. If 120 is indeed a hard limit due to the LinkedBlockingDeque initialization in RadarSimpleReplayBuffer, that should be addressed as well.