Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/constants/relation_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ module RelationTypes
"datacite-crossref",
"crossref",
].freeze

# relation_type_ids that affect counts in lupo.
SOURCE_RELATION_TYPES = ["references", "parts", "versions"].freeze
TARGET_RELATION_TYPES = ["views", "downloads", "citations", "part_of", "version_of"].freeze
end
28 changes: 28 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,32 @@ def obj_hash
indexes :citation_year, type: :integer
indexes :cache_key, type: :keyword
end

class << self
def reindex_touched_dois(start_date:, end_date:, threads: 20)
total = 0

start_date.to_date.upto(end_date.to_date) do |date|
dois = Set.new

where(updated_at: date.all_day)
.where(source_relation_type_id: RelationTypes::SOURCE_RELATION_TYPES)
.distinct.pluck(:source_doi)
.each { |doi| dois << doi }
where(updated_at: date.all_day)
.where(target_relation_type_id: RelationTypes::TARGET_RELATION_TYPES)
.distinct.pluck(:target_doi)
.each { |doi| dois << doi }

# Test performance before enabling SQS queues.
# Parallel.each(dois.to_a, in_threads: threads) do |doi|
# SqsUtilities.send_events_doi_index_message({ doi: doi })
# end

total += dois.size
end

total
end
end
end
5 changes: 5 additions & 0 deletions app/utilities/sqs_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ def send_events_other_doi_job_message(data)
send_message(data, shoryuken_class: "OtherDoiJob", queue_name: "events_other_doi_job")
end

# ReindexDoiJob not implemented yet.
# def send_events_doi_index_message(data)
# send_message(data, shoryuken_class: "ReindexDoiJob", queue_name: "lupo_background")
# end

private

def send_message(body, options = {})
Expand Down
18 changes: 18 additions & 0 deletions lib/tasks/event.rake
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ namespace :event do

puts("Rake task has completed!")
end

desc "Re-queue SQS re-index messages for unique DOIs in events updated within a date range"
# Dates are inclusive. END_DATE defaults to START_DATE for single-day runs.
task reindex_touched_dois: :environment do
raise "START_DATE is required" if ENV["START_DATE"].blank?

start_date = Date.parse(ENV["START_DATE"])
end_date = Date.parse(ENV["END_DATE"].presence || ENV["START_DATE"])

raise "END_DATE must be on or after START_DATE" if end_date < start_date

count = Event.reindex_touched_dois(
start_date: start_date,
end_date: end_date,
)

puts "Sent #{count} unique DOIs for re-indexing."
end
end