Skip to content

Commit

Permalink
Merge pull request #459 from RADAR-base/firebase-improve
Browse files Browse the repository at this point in the history
Improvements for firebase config fetching
  • Loading branch information
this-Aditya authored Sep 30, 2024
2 parents 9587215 + 203df2e commit 2fd6a31
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class FirebaseRemoteConfiguration(private val context: Context, inDevelopmentMod
// activated before newly fetched values are returned.
firebase.activate()
.addOnSuccessListener {
lastFetch = System.currentTimeMillis()
cache = firebase.getKeysByPrefix("")
.mapNotNull { key ->
firebase.getValue(key).asString()
Expand All @@ -91,11 +92,11 @@ class FirebaseRemoteConfiguration(private val context: Context, inDevelopmentMod
* @param maxCacheAge seconds
* @return fetch task or null status is [RadarConfiguration.RemoteConfigStatus.UNAVAILABLE].
*/
override fun doFetch(maxCacheAge: Long) {
override fun doFetch(maxCacheAgeMillis: Long) {
if (status == RadarConfiguration.RemoteConfigStatus.UNAVAILABLE) {
return
}
val task = firebase.fetch(maxCacheAge)
val task = firebase.fetch(maxCacheAgeMillis / 1000L)
synchronized(this) {
status = RadarConfiguration.RemoteConfigStatus.FETCHING
task.addOnSuccessListener(onFetchCompleteHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface RemoteConfig {
var lastFetch: Long
val cache: Map<String, String>

fun doFetch(maxCacheAge: Long)
fun doFetch(maxCacheAgeMillis: Long)

fun fetch(maxCacheAge: Long) {
if (lastFetch + maxCacheAge < System.currentTimeMillis()) {
Expand Down

0 comments on commit 2fd6a31

Please sign in to comment.