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]
 | 
			
		||||
  def populate_if_empty!
 | 
			
		||||
    return unless database.empty?
 | 
			
		||||
 | 
			
		||||
    Formula.each { |f| update!(f.full_name, f.desc) }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
@ -39,6 +40,7 @@ class DescriptionCacheStore < CacheStore
 | 
			
		||||
  # @param  [Report] report: an update report generated by cmd/update.rb
 | 
			
		||||
  # @return [nil]
 | 
			
		||||
  def update_from_report!(report)
 | 
			
		||||
    return populate_if_empty! if database.empty?
 | 
			
		||||
    return if report.empty?
 | 
			
		||||
 | 
			
		||||
    renamings   = report.select_formula(:R)
 | 
			
		||||
@ -56,11 +58,12 @@ class DescriptionCacheStore < CacheStore
 | 
			
		||||
  # @param  [Array] formula_names: the formulae to update.
 | 
			
		||||
  # @return [nil]
 | 
			
		||||
  def update_from_formula_names!(formula_names)
 | 
			
		||||
    return populate_if_empty! if database.empty?
 | 
			
		||||
 | 
			
		||||
    formula_names.each do |name|
 | 
			
		||||
      begin
 | 
			
		||||
        update!(name, Formula[name].desc)
 | 
			
		||||
      rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e
 | 
			
		||||
        p e
 | 
			
		||||
      rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
 | 
			
		||||
        delete!(name)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
@ -71,6 +74,8 @@ class DescriptionCacheStore < CacheStore
 | 
			
		||||
  # @param  [Array] formula_names: the formulae to delete.
 | 
			
		||||
  # @return [nil]
 | 
			
		||||
  def delete_from_formula_names!(formula_names)
 | 
			
		||||
    return if database.empty?
 | 
			
		||||
 | 
			
		||||
    formula_names.each(&method(:delete!))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,7 @@ describe DescriptionCacheStore do
 | 
			
		||||
    let(:report) { double(select_formula: [], empty?: false) }
 | 
			
		||||
 | 
			
		||||
    it "reads from the report" do
 | 
			
		||||
      expect(database).to receive(:empty?).at_least(:once).and_return(false)
 | 
			
		||||
      cache_store.update_from_report!(report)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
@ -36,6 +37,7 @@ describe DescriptionCacheStore do
 | 
			
		||||
        desc "desc"
 | 
			
		||||
      end
 | 
			
		||||
      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)
 | 
			
		||||
      cache_store.update_from_formula_names!([f.name])
 | 
			
		||||
    end
 | 
			
		||||
@ -43,6 +45,7 @@ describe DescriptionCacheStore do
 | 
			
		||||
 | 
			
		||||
  describe "#delete_from_formula_names!" do
 | 
			
		||||
    it "deletes the formulae descriptions" do
 | 
			
		||||
      expect(database).to receive(:empty?).and_return(false)
 | 
			
		||||
      expect(database).to receive(:delete).with(formula_name)
 | 
			
		||||
      cache_store.delete_from_formula_names!([formula_name])
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user