description_cache_store: handle empty database.
Don't perform an incremental update from a report or list of formulae if the cache is currently empty. Also, remove some accidentally remaining debugging output.
This commit is contained in:
parent
5f20f76f36
commit
1621eb0b9d
@ -31,6 +31,7 @@ class DescriptionCacheStore < CacheStore
|
|||||||
# @return [nil]
|
# @return [nil]
|
||||||
def populate_if_empty!
|
def populate_if_empty!
|
||||||
return unless database.empty?
|
return unless database.empty?
|
||||||
|
|
||||||
Formula.each { |f| update!(f.full_name, f.desc) }
|
Formula.each { |f| update!(f.full_name, f.desc) }
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ class DescriptionCacheStore < CacheStore
|
|||||||
# @param [Report] report: an update report generated by cmd/update.rb
|
# @param [Report] report: an update report generated by cmd/update.rb
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def update_from_report!(report)
|
def update_from_report!(report)
|
||||||
|
return populate_if_empty! if database.empty?
|
||||||
return if report.empty?
|
return if report.empty?
|
||||||
|
|
||||||
renamings = report.select_formula(:R)
|
renamings = report.select_formula(:R)
|
||||||
@ -56,11 +58,12 @@ class DescriptionCacheStore < CacheStore
|
|||||||
# @param [Array] formula_names: the formulae to update.
|
# @param [Array] formula_names: the formulae to update.
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def update_from_formula_names!(formula_names)
|
def update_from_formula_names!(formula_names)
|
||||||
|
return populate_if_empty! if database.empty?
|
||||||
|
|
||||||
formula_names.each do |name|
|
formula_names.each do |name|
|
||||||
begin
|
begin
|
||||||
update!(name, Formula[name].desc)
|
update!(name, Formula[name].desc)
|
||||||
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e
|
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
|
||||||
p e
|
|
||||||
delete!(name)
|
delete!(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -71,6 +74,8 @@ class DescriptionCacheStore < CacheStore
|
|||||||
# @param [Array] formula_names: the formulae to delete.
|
# @param [Array] formula_names: the formulae to delete.
|
||||||
# @return [nil]
|
# @return [nil]
|
||||||
def delete_from_formula_names!(formula_names)
|
def delete_from_formula_names!(formula_names)
|
||||||
|
return if database.empty?
|
||||||
|
|
||||||
formula_names.each(&method(:delete!))
|
formula_names.each(&method(:delete!))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ describe DescriptionCacheStore do
|
|||||||
let(:report) { double(select_formula: [], empty?: false) }
|
let(:report) { double(select_formula: [], empty?: false) }
|
||||||
|
|
||||||
it "reads from the report" do
|
it "reads from the report" do
|
||||||
|
expect(database).to receive(:empty?).at_least(:once).and_return(false)
|
||||||
cache_store.update_from_report!(report)
|
cache_store.update_from_report!(report)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -36,6 +37,7 @@ describe DescriptionCacheStore do
|
|||||||
desc "desc"
|
desc "desc"
|
||||||
end
|
end
|
||||||
expect(Formulary).to receive(:factory).with(f.name).and_return(f)
|
expect(Formulary).to receive(:factory).with(f.name).and_return(f)
|
||||||
|
expect(database).to receive(:empty?).and_return(false)
|
||||||
expect(database).to receive(:set).with(f.name, f.desc)
|
expect(database).to receive(:set).with(f.name, f.desc)
|
||||||
cache_store.update_from_formula_names!([f.name])
|
cache_store.update_from_formula_names!([f.name])
|
||||||
end
|
end
|
||||||
@ -43,6 +45,7 @@ describe DescriptionCacheStore do
|
|||||||
|
|
||||||
describe "#delete_from_formula_names!" do
|
describe "#delete_from_formula_names!" do
|
||||||
it "deletes the formulae descriptions" do
|
it "deletes the formulae descriptions" do
|
||||||
|
expect(database).to receive(:empty?).and_return(false)
|
||||||
expect(database).to receive(:delete).with(formula_name)
|
expect(database).to receive(:delete).with(formula_name)
|
||||||
cache_store.delete_from_formula_names!([formula_name])
|
cache_store.delete_from_formula_names!([formula_name])
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user