Cache outdated_versions for Formula

Closes #584.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Vlad Shablinsky 2016-08-01 16:31:36 +03:00 committed by Xu Cheng
parent 9754dbada8
commit 072e5df4ed
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE
2 changed files with 19 additions and 14 deletions

View File

@ -1001,24 +1001,28 @@ class Formula
# @private
def outdated_versions(options = {})
@outdated_versions ||= begin
all_versions = []
@outdated_versions ||= Hash.new do |cache, key|
raise Migrator::MigrationNeededError.new(self) if migration_needed?
cache[key] = _outdated_versions(key)
end
@outdated_versions[options]
end
installed_kegs.each do |keg|
version = keg.version
all_versions << version
def _outdated_versions(options = {})
all_versions = []
return [] if pkg_version <= version && !version.head?
end
installed_kegs.each do |keg|
version = keg.version
all_versions << version
head_version = latest_head_version
if head_version
head_version_outdated?(head_version, options) ? all_versions.sort! : []
else
all_versions.sort!
end
return [] if pkg_version <= version && !version.head?
end
head_version = latest_head_version
if head_version && !head_version_outdated?(head_version, options)
[]
else
all_versions.sort
end
end

View File

@ -583,6 +583,7 @@ class OutdatedVersionsTests < Homebrew::TestCase
def reset_outdated_versions
f.instance_variable_set(:@outdated_versions, nil)
f.instance_variable_set(:@outdated_versions_head_fetched, nil)
end
def test_greater_different_tap_installed