tab: use cache to avoid rereading the same files.
Closes Homebrew/homebrew#46400. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
6054666fa6
commit
10c79620c1
@ -9,6 +9,11 @@ require "utils/json"
|
|||||||
# `Tab.create`.
|
# `Tab.create`.
|
||||||
class Tab < OpenStruct
|
class Tab < OpenStruct
|
||||||
FILENAME = "INSTALL_RECEIPT.json"
|
FILENAME = "INSTALL_RECEIPT.json"
|
||||||
|
CACHE = {}
|
||||||
|
|
||||||
|
def self.clear_cache
|
||||||
|
CACHE.clear
|
||||||
|
end
|
||||||
|
|
||||||
def self.create(formula, compiler, stdlib, build)
|
def self.create(formula, compiler, stdlib, build)
|
||||||
attributes = {
|
attributes = {
|
||||||
@ -32,7 +37,7 @@ class Tab < OpenStruct
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.from_file(path)
|
def self.from_file(path)
|
||||||
from_file_content(File.read(path), path)
|
CACHE.fetch(path) { |p| CACHE[p] = from_file_content(File.read(p), p) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_file_content(content, path)
|
def self.from_file_content(content, path)
|
||||||
@ -217,6 +222,7 @@ class Tab < OpenStruct
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write
|
def write
|
||||||
|
CACHE[tabfile] = self
|
||||||
tabfile.atomic_write(to_json)
|
tabfile.atomic_write(to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,10 +20,12 @@ class InstallTests < Homebrew::TestCase
|
|||||||
assert_predicate formula, :installed?
|
assert_predicate formula, :installed?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Tab.clear_cache
|
||||||
refute_predicate Tab.for_keg(keg), :poured_from_bottle
|
refute_predicate Tab.for_keg(keg), :poured_from_bottle
|
||||||
|
|
||||||
yield formula
|
yield formula
|
||||||
ensure
|
ensure
|
||||||
|
Tab.clear_cache
|
||||||
keg.unlink
|
keg.unlink
|
||||||
keg.uninstall
|
keg.uninstall
|
||||||
formula.clear_cache
|
formula.clear_cache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user