Skip to content

Commit

Permalink
adding cache for speed up the process
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Oct 6, 2019
1 parent c4b90b1 commit fef91dc
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/jobs/event_registrant_update_by_id_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def perform(id, options={})

case item.source_id
when "datacite-crossref"
registrant_id = get_crossref_member_id(item.obj_id) if get_doi_ra(item.obj_id) == "Crossref"
registrant_id = cached_get_crossref_member_id(item.obj_id) if cached_get_doi_ra(item.obj_id) == "Crossref"
logger.info registrant_id

obj = item.obj.merge("registrant_id" => registrant_id) unless registrant_id.nil?
logger.info obj
item.update_attributes(obj: obj) if obj.present?
when "crossref"
registrant_id = get_crossref_member_id(item.subj_id) if get_doi_ra(item.subj_id) == "Crossref"
registrant_id = cached_get_crossref_member_id(item.subj_id) if cached_get_doi_ra(item.subj_id) == "Crossref"
logger.info registrant_id

subj = item.subj.merge("registrant_id" => registrant_id) unless registrant_id.nil?
Expand Down Expand Up @@ -53,6 +53,20 @@ def get_crossref_member_id(id, options={})
"crossref.#{message["member"]}"
end

def cached_get_doi_ra(doi)
Rails.cache.fetch("ras/#{doi}") do
puts "did not find key in cache, executing block ..."
get_doi_ra(doi)
end
end

def cached_get_crossref_member_id(doi)
Rails.cache.fetch("members_ids/#{doi}") do
puts "did not find key in cache, executing block ..."
get_crossref_member_id(doi)
end
end

def get_doi_ra(doi)
prefix = validate_prefix(doi)
return nil if prefix.blank?
Expand Down

0 comments on commit fef91dc

Please sign in to comment.