flagship-io / flagship-android

Flagship Android library for implementing campaigns in your native Android app.
Apache License 2.0
7 stars 2 forks source link

Optimization: fetchFlags() sending an API request even when the context hasn't changed #12

Open thomas-herbeth-srp opened 1 month ago

thomas-herbeth-srp commented 1 month ago

Flagship Version: 3.1.0 Bucketing mode

Hello. We have noticed an intriguing behavior when updating the Flagship context. Let's suppose we have this context: {"foo": "foo", "bar": "bar"} And we update the context like so:

suspend fun updateContext(context: HashMap<String, Any>) {
    visitor.updateContext(context)
    visitor.fetchFlags().await()
}

updateContext(hashMapOf("foo" to "foo"))

Then we can see in the logs that fetchFlags() sends an API request to https://decision.flagship.io/v2/xxxxx/events, even though the context hasn't changed.

It doesn't look like fetchFlags() checks for context modification (visitor.flagFetchingStatus) before sending the API request, so it sends requests that are not necessary: https://github.com/flagship-io/flagship-android/blob/10922824e4d44c5d50d47edc63b22a1729d1fd44/flagship/src/main/java/com/abtasty/flagship/visitor/DefaultStrategy.kt#L69

Would it be possible to optimize fetchFlags() to only update flags when necessary, or add restrictions to avoid sending too many API requests? Thanks.

raf-abtasty commented 1 month ago

Hi @thomas-herbeth-srp thx for your feedback, good news this improvement is already planed in our roadmap. No ETA yet stay tuned.