Skip to content

Commit 04724d3

Browse files
authored
Merge pull request #212 from mlibrary/solr_admin_timeout_ttl
Use a memoizing ttl library to reduce solr calls
2 parents 626e6ad + f3731d0 commit 04724d3

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ gem "aws-sdk-s3", "~> 1.160"
2121
gem "content_disposition", "~> 1.0"
2222
gem "uppy-s3_multipart", "~> 1.2"
2323

24+
gem "ttl_memoizeable"
2425

2526
#####################################
2627
# Try to work around brokenness on

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ GEM
410410
slop (~> 4.0)
411411
yell
412412
transproc (1.1.1)
413+
ttl_memoizeable (0.4.0)
414+
activesupport
413415
twitter-typeahead-rails (0.11.1.pre.corejavascript)
414416
actionpack (>= 3.1)
415417
jquery-rails
@@ -498,6 +500,7 @@ DEPENDENCIES
498500
sqlite3 (~> 1.3.13)
499501
standard
500502
traject
503+
ttl_memoizeable
501504
tzinfo-data
502505
uglifier (>= 1.3.0)
503506
uppy-s3_multipart (~> 1.2)

app/views/shared/_footer.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
Data last refreshed <%= if Dromedary::Services[:looks_like_first_upload]
4040
"never"
4141
else
42-
Dromedary.collection_creation_date.strftime("%A, %B %-e, %Y")
42+
Dromedary.collection_creation_date_string
4343
end
4444
%>.
4545
</p>

config/load_local_config.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
require_relative "../lib/med_installer/logger"
44
require_relative "../lib/dromedary/services"
55
require_relative "../lib/med_installer/hyp_to_bibid"
6+
require "ttl_memoizeable"
67

78
module 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)

indexer/main_indexing_rules.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
provide "solr_writer.basic_auth_password", Dromedary::Services[:solr_password]
2020
end
2121

22-
hyp_to_bibid = Dromedary.hyp_to_bibid(collection: Dromedary::Services[:solr_collection_to_index_into])
22+
hyp_to_bibid = MedInstaller::HypToBibId.get_from_solr(collection: Dromedary::Services[:solr_collection_to_index_into])
2323
bibset = MiddleEnglishDictionary::Collection::BibSet.new(filename: settings["bibfile"])
2424

2525
# Do a terrible disservice to traject and monkeypatch it to take

0 commit comments

Comments
 (0)