Skip to content

Memoize falsy values #30

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

Merged
merged 2 commits into from
Sep 4, 2015
Merged

Memoize falsy values #30

merged 2 commits into from
Sep 4, 2015

Conversation

spraints
Copy link
Member

@spraints spraints commented Sep 3, 2015

Ruby treats nil and false the same when they're on the left hand side of a ||=. There are a couple of slow bits of code that are supposed to run once, but could run on each call, if they return nil or false. This branch changes them to be more explicit about how they handle their instance variables to ensure that the falsy results don't lead to a retry on the next call.

  • #dns - This can be an array of results or nil. Before this branch, @dns == nil initially and if the dns results should be nil. This branch changes the latter case to set @dns = false, and it checks explicitly for @dns.nil? to know if it should actually look up any values.
  • #served_by_pages? - This will return true or false. Before this branch, @served_by_pages would be nil on init and a boolean after the check had been run. The check ran any time @served_by_pages was nil or false. This branch changes it so that the check only runs when @served_by_pages.nil?.

cc @benbalter

@benbalter
Copy link
Contributor

TIL. Thanks for taking the time to document this as well... learned a lot. 👍

@benbalter
Copy link
Contributor

Hey, also to call myself out, I should have left #29 for at least a day. Thought it was simple enough, and was trying to fix an internal error, but neither are an excuse for not being collaborative. Thanks for the 👀 despite my best efforts. 😸

@spraints
Copy link
Member Author

spraints commented Sep 4, 2015

Hey, also to call myself out, I should have left #29 for at least a day.

Eh, this is no big deal, most of the time. #29 was an improvement, and this PR builds on that to make it a little bit better. Review and iteration can span multiple PRs.

benbalter added a commit that referenced this pull request Sep 4, 2015
@benbalter benbalter merged commit 185a109 into master Sep 4, 2015
@benbalter benbalter deleted the memoize-nil branch September 4, 2015 12:50
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