Skip to content
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

Use flags_by key for faster access #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

webjunkie
Copy link

No description provided.

except Exception as e:
self.log.exception(f"[FEATURE FLAGS] Error while computing variant locally: {e}")
continue
flag = self.feature_flags_by_key.get(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is feature_flags_by_key is not guaranteed to be populated here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I may be wrong. I think the problem is we have a lot of unit tests that only set self.client.feature_flags and do not set self.feature_flags_by_key.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better solution would be to make feature_flags a @property. That way, we can pre-populate other related properties when it's set. Something like:

@property
    def feature_flags(self):
        return self._feature_flags

    @feature_flags.setter 
    def feature_flags(self, value):
        self._feature_flags = value
        self.feature_flags_by_key = {
            flag["key"]: flag for flag in (value or []) if flag.get("key") is not None
        }

That way, we won't need to update every unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants