Conversation
| private | ||
|
|
||
| def now | ||
| @now ||= Time.now |
There was a problem hiding this comment.
Why aren't we just setting this on the initialize?
There was a problem hiding this comment.
Same answer - if you never get a on: date then we don't need to create this object.
lib/smart_todo/events.rb
Outdated
| def rubygems_client | ||
| @rubygems_client ||= Net::HTTP.new("rubygems.org", Net::HTTP.https_default_port).tap do |client| | ||
| client.use_ssl = true | ||
| end | ||
| end | ||
|
|
||
| def github_client | ||
| @github_client ||= Net::HTTP.new("api.github.com", Net::HTTP.https_default_port).tap do |client| | ||
| client.use_ssl = true | ||
| end | ||
| end | ||
|
|
||
| def installed_ruby_version | ||
| @installed_ruby_version ||= Gem::Version.new(RUBY_VERSION) |
There was a problem hiding this comment.
Why aren't we setting those in the initialize?
There was a problem hiding this comment.
We're lazily setting these up because if you don't find any todos that have a gem version, there's no need to instantiate these objects. Basically it mirrors the previous behavior of lazily creating objects based on the todos you find.
lib/smart_todo/events/date.rb
Outdated
| # @return [String, false] | ||
| def met?(on_date) | ||
| if Time.now >= Time.parse(on_date) | ||
| def met?(on_date, now = Time.now) |
There was a problem hiding this comment.
Do we even use this method without the second argument?
There was a problem hiding this comment.
We don't, I just wasn't sure how much you wanted to break the existing APIs. Happy to make this required if you're prefer.
There was a problem hiding this comment.
It is fine to break API, all those classes are private API.
There was a problem hiding this comment.
Nice, in this case I've inlined the classes.
lib/smart_todo/events/gem_bump.rb
Outdated
| # @example Expecting a version in the 5.x.x series | ||
| # GemBump.new('rails', ['> 5.2', '< 6']) | ||
| def initialize(gem_name, requirements) | ||
| def initialize(gem_name, requirements, spec_set = Bundler.load.specs) |
There was a problem hiding this comment.
Do we use this class without the last argument?
There was a problem hiding this comment.
Nope, removed the class wholesale.
lib/smart_todo/events/gem_release.rb
Outdated
| # @example Expecting a version in the 5.x.x series | ||
| # GemRelease.new('rails', ['> 5.2', '< 6']) | ||
| def initialize(gem_name, requirements) | ||
| def initialize(gem_name, requirements, client = nil) |
lib/smart_todo/events/issue_close.rb
Outdated
| # @param repo [String] | ||
| # @param pr_number [String, Integer] | ||
| def initialize(organization, repo, pr_number, type:) | ||
| def initialize(organization, repo, pr_number, client = nil, type:) |
| def initialize(requirements) | ||
| attr_reader :installed_ruby_version | ||
|
|
||
| def initialize(requirements, installed_ruby_version = Gem::Version.new(RUBY_VERSION)) |
|
Just one sec - I released the new version of Prism so I'll make it point to rubygems.org |
|
@rafaelfranca this is good to go now. Should I merge? |
|
Yes. |
👋 Hi! I heard this could benefit from some improved performance, and also that it used ripper. I'm on a mission to remove ripper from everywhere. So, I took a look. I did a couple of things to improve performance, namely:
Eventsfrom a module to a class. Previously, every event on every todo lined up to a method call to theEventsmodule. That module would then instantiate whatever data it needed to do its job. But none of this data could be shared between todos. So it was discarded when the method call returned. Now instead we cache the data we want to keep around (like rubygems or github clients).There are still quite a few improvements I think could be put in place, but this seemed like a good place to stop. Those would be:
Overall, with these improvements in place, the time to parse Shopify's monolith on my computer went from
1:26.26to22.789:A couple of things to note:
Sorry about the size of this PR. I saw a bunch of stuff so I just kept going. Happy to trim this back to individual small commits if you'd prefer. I just figured I'd get this in front of eyes now and then we can reevaluate the scope of it.