33require_relative "../lib/med_installer/logger"
44require_relative "../lib/dromedary/services"
55require_relative "../lib/med_installer/hyp_to_bibid"
6+ require "ttl_memoizeable"
67
78module Dromedary
89 class << self
10+ extend TTLMemoizeable
911 def logger
10- MedInstaller ::Logger ::LOGGER
12+ Rails . logger || MedInstaller ::Logger ::LOGGER
1113 end
1214
1315 # For whatever historical reasons, this uses the Ettin gem to load
@@ -26,34 +28,32 @@ def config
2628 ENV [ "RAILS_ENV" ]
2729 else
2830 "development"
29- end
31+ end
3032 @config = Dromedary ::Services
3133 end
3234
33- def hyp_to_bibid ( collection : Dromedary ::Services [ :solr_current_collection ] )
34- logger . info "Trying to get hyp_to_bibid for collection #{ collection } "
35- current_real_collection_name = underlying_real_collection_name ( coll : collection )
36- logger . info "Real collection name identified as #{ current_real_collection_name } "
37- if @recorded_real_collection_name != current_real_collection_name
38- @hyp_to_bibid = MedInstaller ::HypToBibId . get_from_solr ( collection : collection )
39- @recorded_real_collection_name = current_real_collection_name
40- @collection_creation_date = nil
41- end
42- @hyp_to_bibid
4335
36+ def hyp_to_bibid
37+ collection = Dromedary ::Services [ :solr_current_collection ]
38+ Rails . logger . warn "################# Fetching HyperBib ########################"
39+ MedInstaller ::HypToBibId . get_from_solr ( collection : collection )
4440 end
4541
46- # @param coll [SolrCloud::Alias]
47- def underlying_real_collection_name ( coll : Dromedary ::Services [ :solr_current_collection ] )
48- return coll . name unless coll . alias?
49- underlying_real_collection_name ( coll : coll . collection )
42+ def collection_creation_date
43+ Rails . logger . warn "################# Fetching creation date ########################"
44+ collection = Dromedary ::Services [ :solr_current_collection ]
45+ if collection
46+ Dromedary . compute_collection_creation_date collection . collection . name
47+ else
48+ "Never"
49+ end
5050 end
5151
52- def collection_creation_date ( coll : Dromedary :: Services [ :solr_current_collection ] )
53- return @ collection_creation_date if defined? ( @collection_creation_date ) && ! @collection_creation_date . nil?
52+ ttl_memoized_method :hyp_to_bibid , ttl : 20 . seconds
53+ ttl_memoized_method : collection_creation_date, ttl : 20 . seconds
5454
55- real_collection_name = underlying_real_collection_name ( coll : coll )
56- @ collection_creation_date = compute_collection_creation_date ( real_collection_name )
55+ def collection_creation_date_string
56+ collection_creation_date . strftime ( "%A, %B %-e, %Y at %H:%M:%S" )
5757 end
5858
5959 def compute_collection_creation_date ( coll )
0 commit comments