Skip to content

Commit

Permalink
Merge pull request #392 from ivplus/short-circuit-stats
Browse files Browse the repository at this point in the history
Don't run the UpdateOrganizationStatisticsJob if additional uploads h…
  • Loading branch information
corylown authored Oct 26, 2021
2 parents 40b2f10 + 71f7511 commit 206e84f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/jobs/extract_marc_record_metadata_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def perform(upload)
end
end

UpdateOrganizationStatisticsJob.perform_later(upload.organization, upload.stream)
UpdateOrganizationStatisticsJob.perform_later(upload.organization, upload.stream, upload)
end
# rubocop:enable Metrics/AbcSize

Expand Down
9 changes: 8 additions & 1 deletion app/jobs/update_organization_statistics_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ def self.perform_all
Organization.find_each { |o| perform_later(o) }
end

def perform(organization, stream = nil)
def perform(organization, stream = nil, upload = nil)
stream ||= organization.default_stream

# short-circuit if our statstics job is already obsolete
return if upload && stream.uploads.where('created_at > ?', upload.created_at)

generate_statistics!(organization, stream)
end

def generate_statistics!(organization, stream)
stream_statistics = stream.statistic || stream.create_statistic
stream_statistics.update(date: Time.zone.today, **calculate_stream_statistics(stream))

Expand Down

0 comments on commit 206e84f

Please sign in to comment.