Skip to content

Commit

Permalink
Merge pull request #212 from mlibrary/solr_admin_timeout_ttl
Browse files Browse the repository at this point in the history
Use a memoizing ttl library to reduce solr calls
  • Loading branch information
billdueber authored Oct 21, 2024
2 parents 626e6ad + f3731d0 commit 04724d3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gem "aws-sdk-s3", "~> 1.160"
gem "content_disposition", "~> 1.0"
gem "uppy-s3_multipart", "~> 1.2"

gem "ttl_memoizeable"

#####################################
# Try to work around brokenness on
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ GEM
slop (~> 4.0)
yell
transproc (1.1.1)
ttl_memoizeable (0.4.0)
activesupport
twitter-typeahead-rails (0.11.1.pre.corejavascript)
actionpack (>= 3.1)
jquery-rails
Expand Down Expand Up @@ -498,6 +500,7 @@ DEPENDENCIES
sqlite3 (~> 1.3.13)
standard
traject
ttl_memoizeable
tzinfo-data
uglifier (>= 1.3.0)
uppy-s3_multipart (~> 1.2)
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Data last refreshed <%= if Dromedary::Services[:looks_like_first_upload]
"never"
else
Dromedary.collection_creation_date.strftime("%A, %B %-e, %Y")
Dromedary.collection_creation_date_string
end
%>.
</p>
Expand Down
40 changes: 20 additions & 20 deletions config/load_local_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
require_relative "../lib/med_installer/logger"
require_relative "../lib/dromedary/services"
require_relative "../lib/med_installer/hyp_to_bibid"
require "ttl_memoizeable"

module Dromedary
class << self
extend TTLMemoizeable
def logger
MedInstaller::Logger::LOGGER
Rails.logger || MedInstaller::Logger::LOGGER
end

# For whatever historical reasons, this uses the Ettin gem to load
Expand All @@ -26,34 +28,32 @@ def config
ENV["RAILS_ENV"]
else
"development"
end
end
@config = Dromedary::Services
end

def hyp_to_bibid(collection: Dromedary::Services[:solr_current_collection])
logger.info "Trying to get hyp_to_bibid for collection #{collection}"
current_real_collection_name = underlying_real_collection_name(coll: collection)
logger.info "Real collection name identified as #{current_real_collection_name}"
if @recorded_real_collection_name != current_real_collection_name
@hyp_to_bibid = MedInstaller::HypToBibId.get_from_solr(collection: collection)
@recorded_real_collection_name = current_real_collection_name
@collection_creation_date = nil
end
@hyp_to_bibid

def hyp_to_bibid
collection = Dromedary::Services[:solr_current_collection]
Rails.logger.warn "################# Fetching HyperBib ########################"
MedInstaller::HypToBibId.get_from_solr(collection: collection)
end

# @param coll [SolrCloud::Alias]
def underlying_real_collection_name(coll: Dromedary::Services[:solr_current_collection])
return coll.name unless coll.alias?
underlying_real_collection_name(coll: coll.collection)
def collection_creation_date
Rails.logger.warn "################# Fetching creation date ########################"
collection = Dromedary::Services[:solr_current_collection]
if collection
Dromedary.compute_collection_creation_date collection.collection.name
else
"Never"
end
end

def collection_creation_date(coll: Dromedary::Services[:solr_current_collection])
return @collection_creation_date if defined?(@collection_creation_date) && !@collection_creation_date.nil?
ttl_memoized_method :hyp_to_bibid, ttl: 20.seconds
ttl_memoized_method :collection_creation_date, ttl: 20.seconds

real_collection_name = underlying_real_collection_name(coll: coll)
@collection_creation_date = compute_collection_creation_date(real_collection_name)
def collection_creation_date_string
collection_creation_date.strftime("%A, %B %-e, %Y at %H:%M:%S")
end

def compute_collection_creation_date(coll)
Expand Down
2 changes: 1 addition & 1 deletion indexer/main_indexing_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
provide "solr_writer.basic_auth_password", Dromedary::Services[:solr_password]
end

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

# Do a terrible disservice to traject and monkeypatch it to take
Expand Down

0 comments on commit 04724d3

Please sign in to comment.