From ff02c70df92620871417e49ed939415988c275ba Mon Sep 17 00:00:00 2001 From: "Ben W. Brumfield" Date: Tue, 24 Oct 2023 11:09:57 -0500 Subject: [PATCH] Address performance of #3799 by using activity summary table instead of deeds --- app/controllers/dashboard_controller.rb | 2 +- app/models/collection.rb | 1 + app/models/user.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 578f29ad2d..bc22f2c98a 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -114,7 +114,7 @@ def summary # Collaborator Dashboard - watchlist def watchlist works = Work.joins(:deeds).where(deeds: { user_id: current_user.id }).distinct - collections = Collection.joins(:deeds).where(deeds: { user_id: current_user.id }).distinct.order_by_recent_activity.limit(5) + collections = Collection.where(id: current_user.ahoy_activity_summaries.pluck(:collection_id)).distinct.order_by_recent_activity.limit(5) document_sets = DocumentSet.joins(works: :deeds).where(works: { id: works.ids }).order('deeds.created_at DESC').distinct.limit(5) collections_list(true) # assigns @collections_and_document_sets for private collections only @collections = (collections + document_sets).sort { |a, b| a.title <=> b.title }.take(5) diff --git a/app/models/collection.rb b/app/models/collection.rb index 83ffe201de..fa02b7b250 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -36,6 +36,7 @@ class Collection < ApplicationRecord has_and_belongs_to_many :owners, :class_name => 'User', :join_table => :collection_owners has_and_belongs_to_many :collaborators, :class_name => 'User', :join_table => :collection_collaborators has_and_belongs_to_many :reviewers, :class_name => 'User', :join_table => :collection_reviewers + has_many :ahoy_activity_summaries validates :title, presence: true, length: { minimum: 3, maximum: 255 } validates :slug, format: { with: /[[:alpha:]]/ } diff --git a/app/models/user.rb b/app/models/user.rb index 5c9243ecb0..f4b06183be 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,6 +30,7 @@ class User < ApplicationRecord has_many :collection_blocks, dependent: :destroy has_many :blocked_collections, through: :collection_blocks, source: :collection + has_many :ahoy_activity_summaries has_and_belongs_to_many(:scribe_works, :join_table => 'transcribe_authorizations',