NTP-16109-caching-mechanism-for-scratch-card-config (#13850)
This commit is contained in:
@@ -19,6 +19,7 @@ import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper.UPI_SCRAT
|
||||
import com.navi.common.forge.model.ScreenDefinition
|
||||
import com.navi.common.model.RequestConfig
|
||||
import com.navi.common.network.models.RepoResult
|
||||
import com.navi.common.network.models.isSuccessWithData
|
||||
import com.navi.common.utils.NaviApiPoller
|
||||
import com.navi.common.utils.isValidResponse
|
||||
import com.navi.common.utils.log
|
||||
@@ -42,6 +43,8 @@ import com.navi.rr.utils.injector.FieldInjector
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import kotlin.time.DurationUnit
|
||||
import kotlin.time.toDuration
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.cancel
|
||||
@@ -165,9 +168,31 @@ constructor(
|
||||
return callbackFlow {
|
||||
val userId = PreferenceManager.getStringPreference(CommonPrefConstants.USER_ID)
|
||||
val forgeResponse = async {
|
||||
scratchCardRepo.fetchScratchCardTemplate(
|
||||
metricInfo = MetricInfo.RewardMetric(screen = screenName, isNae = { false })
|
||||
)
|
||||
val currentValueInDb = naviCacheRepository.get(SCRATCH_CARD_UI_CONFIG)?.value
|
||||
if (currentValueInDb != null) {
|
||||
val dbResponse = gson.fromJson(currentValueInDb, ScreenDefinition::class.java)
|
||||
RepoResult(dbResponse)
|
||||
} else {
|
||||
val networkResponse =
|
||||
scratchCardRepo.fetchScratchCardTemplate(
|
||||
metricInfo =
|
||||
MetricInfo.RewardMetric(screen = screenName, isNae = { false })
|
||||
)
|
||||
if (networkResponse.isSuccessWithData()) {
|
||||
naviCacheRepository.save(
|
||||
naviCacheEntity =
|
||||
NaviCacheEntity(
|
||||
key = SCRATCH_CARD_UI_CONFIG,
|
||||
value = gson.toJson(networkResponse.data),
|
||||
version = 1,
|
||||
ttl = 1.toDuration(DurationUnit.DAYS).inWholeMilliseconds
|
||||
)
|
||||
)
|
||||
} else {
|
||||
send(GratificationStatus.Timeout())
|
||||
}
|
||||
networkResponse
|
||||
}
|
||||
}
|
||||
eventTracker.sendEvent(SCRATCH_CARD_GET_GRATIFICATION_CALLED)
|
||||
val responseProcessed = AtomicBoolean(false)
|
||||
@@ -365,11 +390,8 @@ constructor(
|
||||
|
||||
companion object {
|
||||
private const val SCRATCH_CARD_OVERLAY_SCREEN_NAME = "SCRATCH_CARD_OVERLAY_SCREEN_NAME"
|
||||
private const val CURRENT_BALANCE = "currentBalance"
|
||||
private const val PREVIOUS_BALANCE = "previousBalance"
|
||||
private const val TRANSACTION_ID = "transaction_id"
|
||||
private const val SCREEN_NAME = "screen_name"
|
||||
private const val PAYMENT_SUMMARY_SCREEN = "PAYMENT_SUMMARY_SCREEN"
|
||||
private const val REWARD_EARNED = "reward_earned"
|
||||
private const val Y = "Y"
|
||||
private const val N = "N"
|
||||
@@ -396,5 +418,7 @@ constructor(
|
||||
private const val DEV_REWARDS_ON_UPI_POLLING_EXCEPTION = "dev_reward_upi_polling_exception"
|
||||
private const val DEV_REWARDS_ON_UPI_COLLECT_EXCEPTION =
|
||||
"dev_reward_upi_on_collect_exception"
|
||||
|
||||
private const val SCRATCH_CARD_UI_CONFIG = "scratchCardUiConfig"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user