-
Notifications
You must be signed in to change notification settings - Fork 16
feat: change cache to use Map<String, Flag> instead of Set<Flag> #68
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: main
Are you sure you want to change the base?
Conversation
…ing is the feature name.
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.
Looks like a significant improvement! Added a few suggestions to contribute to performance and readability.
@@ -357,7 +356,7 @@ class FlagsmithClient { | |||
Future<bool> removeFeatureFlag(String featureName) async { | |||
var result = await storageProvider.delete(featureName); | |||
if (config.caches) { | |||
_flags.removeWhere((element) => element.feature.name == featureName); | |||
_flags.removeWhere((key, _) => key == featureName); |
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.
_flags.removeWhere((key, _) => key == featureName); | |
_flags.remove(featureName); |
if (config.caches) { | ||
_flags.removeWhere((element) => element.feature.name == featureName); | ||
_flags.removeWhere((key, _) => key == featureName); | ||
if (value != null) { | ||
_flags.add(value); | ||
_flags[value.feature.name] = value; | ||
} |
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.
if (config.caches && value != null) {
_flags[featureName] = value;
}
final newData = <String, Flag>{}; | ||
for (var element in list) { | ||
newData[element.feature.name] = element; | ||
} | ||
|
||
_flags | ||
..clear() | ||
..addAll(newData); |
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.
final newData = <String, Flag>{}; | |
for (var element in list) { | |
newData[element.feature.name] = element; | |
} | |
_flags | |
..clear() | |
..addAll(newData); | |
_flags.clear(); | |
list.forEach((element) => _flags[element.feature.name] = element); |
We don't need the addAll
after all. Feel free to keep the bare for
syntax.
Hi.
I realised that the cached uses quite a number of
firstWhereOrNull
for lookup. This PR changes to use Map so that getting flag value will be in O(1). I am currently thinking of using this but would also like some opinion from original maintainer on this idea :)Unit test result