diff --git a/app/decorators/work_decorator.rb b/app/decorators/work_decorator.rb index 458b7b51..8a1b5b90 100644 --- a/app/decorators/work_decorator.rb +++ b/app/decorators/work_decorator.rb @@ -10,7 +10,7 @@ class WorkDecorator def initialize(work, current_user) @work = work @current_user = current_user - @changes = WorkActivity.changes_for_work(work.id) + @changes = WorkActivity.changes_for_work(work.id).order(created_at: :asc) @messages = WorkActivity.messages_for_work(work.id).order(created_at: :desc) @can_curate = current_user&.can_admin?(group) end diff --git a/app/models/work.rb b/app/models/work.rb index 475c3660..281a0f4d 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -292,13 +292,19 @@ def new_notification_count_for_user(user_id) # In practice, the user_id is the id of the current user and therefore this method marks the current's user # notifications as read. def mark_new_notifications_as_read(user_id) - activities.each do |activity| - unread_notifications = WorkActivityNotification.where(user_id:, work_activity_id: activity.id, read_at: nil) - unread_notifications.each do |notification| - notification.read_at = Time.now.utc - notification.save - end - end + # Notice that we fetch and update the information in batches + # so that we don't issue individual SQL SELECT + SQL UPDATE + # for each notification. + # + # Rails batching information: + # https://guides.rubyonrails.org/active_record_querying.html + # https://api.rubyonrails.org/classes/ActiveRecord/Batches.html + + # Disable this validation since we want to force a SQL UPDATE. + # rubocop:disable Rails/SkipsModelValidations + now_utc = Time.now.utc + WorkActivityNotification.joins(:work_activity).where("user_id=? and work_id=?", user_id, id).in_batches(of: 1000).update_all(read_at: now_utc) + # rubocop:enable Rails/SkipsModelValidations end def current_transition diff --git a/app/models/work_activity.rb b/app/models/work_activity.rb index 723f1743..1727d2c1 100644 --- a/app/models/work_activity.rb +++ b/app/models/work_activity.rb @@ -79,7 +79,6 @@ def users_referenced def created_by_user return nil unless created_by_user_id - User.find(created_by_user_id) end diff --git a/app/views/works/_work_activity_provenance.html.erb b/app/views/works/_work_activity_provenance.html.erb index 569aed4b..1509f7c9 100644 --- a/app/views/works/_work_activity_provenance.html.erb +++ b/app/views/works/_work_activity_provenance.html.erb @@ -4,12 +4,15 @@ No activity <% end %>
There are <%= @work_decorator.changes.size - 100 %> more notifications, contact RDSS if you need to view them.
+ <% end %> <% if can_add_provenance_note %> <%= form_with url: add_provenance_note_path(@work) do |f| %> @@ -34,7 +37,7 @@