Class: SampleManifestExcel::Upload::Cache
- Inherits:
-
Object
- Object
- SampleManifestExcel::Upload::Cache
- Defined in:
- app/sample_manifest_excel/sample_manifest_excel/upload/cache.rb
Overview
In order to optimize performance and avoid n+1 query problems we load all our information upfront
Instance Method Summary collapse
- #find_by(options) ⇒ Object
-
#initialize(base) ⇒ Cache
constructor
A new instance of Cache.
- #populate! ⇒ Object
Constructor Details
#initialize(base) ⇒ Cache
Returns a new instance of Cache.
10 11 12 13 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/cache.rb', line 10 def initialize(base) @base = base @manifest_assets = {} end |
Instance Method Details
#find_by(options) ⇒ Object
19 20 21 22 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/cache.rb', line 19 def find_by() populate! if @manifest_assets.empty? && @base.sample_manifest.present? @manifest_assets[.fetch(:sanger_sample_id)] end |
#populate! ⇒ Object
15 16 17 |
# File 'app/sample_manifest_excel/sample_manifest_excel/upload/cache.rb', line 15 def populate! @manifest_assets = @base.sample_manifest.indexed_manifest_assets end |