Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the GraduationService for improved performance #2121

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 7 additions & 10 deletions app/services/graduation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@ def self.load_data(path_to_data)
@registrar_data = JSON.parse(File.read(path_to_data))
end

# Find all Etds in the 'approved' workflow state that do not yet have a degree_awarded value
# Find all Etds in the 'approved' workflow state that are eligible for graduation
# @return [Array<Etd>] An Array of ETD objects
def self.graduation_eligible_works
eligible_works = []
problem_works = []
no_degree_yet = Etd.where(degree_awarded: nil).to_a
no_degree_yet.each do |etd|
begin
eligible_works << etd if etd.to_sipity_entity.workflow_state_name == 'approved'
rescue
problem_works << etd.id
# Use #search_in_batches to avoid timeouts in the case where there are a large number of ETDs
# that have been approved and are pending grqaduation (i.e. publication)
Etd.search_in_batches({ workflow_state_name_ssim: 'approved' }, batch_size: 50) do |batch|
batch.each do |doc|
eligible_works << Etd.find(doc['id'])
end
end

Rails.logger.warn "Graduation service: There were #{eligible_works.count} ETDs eligible for graduation"
Rails.logger.warn "Graduation service: There were #{problem_works.count} where the workflow status could not be queried."
Rails.logger.error "Graduation service: Could not query workflow status for these works: #{problem_works.inspect}" if problem_works.count > 0
eligible_works
end

Expand Down
6 changes: 0 additions & 6 deletions app/services/graduationdate_service.rb

This file was deleted.