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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only using request-level cache if the helper has a request #27

Closed
wants to merge 1 commit into from

Conversation

ponny
Copy link

@ponny ponny commented Jun 3, 2020

Firstly, thanks for building such a great gem. The interface is quite intuitive and the source code is very clear. It's really been useful for our team in adding A/B tests (and sometimes feature toggling). We've introduced many improvements based on the results in the last few months. 馃檹

This is my first open source pull request so please let me know if I'm 'doing it wrong' 馃槃

We had an issue where we were using FieldTest::Helpers in a service with class methods.

class SomeService
  extend FieldTest::Helpers

  class << self
    def variant!(user)
      field_test("my_experiment_name", participant: user)
    end
end

Unfortunately, this meant that our app cached the result in @field_test_cache per experiment permanently (until the app restarts anyway). Looking at the comments inside FieldTest::Helpers#field_test, it seems to be setting the cache for the request outside of the check for the request. This fix means that it will only be using the cache when a request is present.

I also added a tweak to the assignment of params_variant because it could be unassigned. Happy to roll it back if you don't like doing it that way.

@ponny ponny changed the title Not using request-level cache if the helper is not in a request Only using request-level cache if the helper has a request Jun 3, 2020
@ankane
Copy link
Owner

ankane commented Jun 3, 2020

Hey @ponny, thanks for the PR (and congrats 馃帀)! For non-requests, there's a different method that's preferred that skips caching (as the Helper module itself isn't meant to be public): https://github.com/ankane/field_test#jobs

For requests, it looks like the cache key needs to take participants and possibly a few other options that affect the variant like exclude into account. Feel free to update the PR if that's something you'd like to tackle.

Re params_variant: it's generally a good practice to keep the changeset to a minimum, as it makes it easier to review/merge and each author has their own preferred style.

@ponny
Copy link
Author

ponny commented Jun 10, 2020

Fair enough. Thanks for the advice 馃憤

@ponny ponny closed this Jun 10, 2020
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.

None yet

2 participants