Skip to content

Commit

Permalink
refactor: move shouldApply logic higher in the stack call
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko committed Feb 5, 2025
1 parent 05b0285 commit 8a4b5d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Confidence/src/main/java/com/spotify/confidence/Confidence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class Confidence internal constructor(
* @param resolveToken resolve token.
* @param shouldApply whether to send an apply event or not
*/
fun apply(flagName: String, resolveToken: String, shouldApply: Boolean) {
flagApplier.apply(flagName, resolveToken, shouldApply)
fun apply(flagName: String, resolveToken: String) {
flagApplier.apply(flagName, resolveToken)
debugLogger?.logFlag("Apply", flagName)
}

Expand All @@ -116,10 +116,12 @@ class Confidence internal constructor(
key,
default,
evaluationContext
) { flagName, resolveToken, shouldApply ->
) { flagName, resolveToken, shouldApply->
// this lambda will be invoked inside the evaluation process
// and only if the resolve reason is not targeting key error.
apply(flagName, resolveToken, shouldApply)
if (shouldApply) {
apply(flagName, resolveToken)
}
}
// we are using a custom serializer so that the Json is serialized correctly in the logs
val newMap: Map<String, @Serializable(NetworkConfidenceValueSerializer::class) ConfidenceValue> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.spotify.confidence.apply

interface FlagApplier {
fun apply(flagName: String, resolveToken: String, shouldApply: Boolean)
fun apply(flagName: String, resolveToken: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ class FlagApplierWithRetries(
eventProcessor.start()
}

override fun apply(flagName: String, resolveToken: String, shouldApply: Boolean) {
if (shouldApply) {
override fun apply(flagName: String, resolveToken: String) {
eventProcessor.apply(FlagApplierInput(resolveToken, flagName))
}
}

private fun internalApply(
Expand Down

0 comments on commit 8a4b5d2

Please sign in to comment.