From baf0a218c0cda076a3f4fcd988f4834c64202216 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Thu, 6 May 2021 12:30:56 -0400 Subject: [PATCH] replace AF.where method using solr to count Objects are not needed to count the number of results. Only using solr to count. rc --- .../hyrax/dashboard_helper_behavior.rb | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/helpers/hyrax/dashboard_helper_behavior.rb b/app/helpers/hyrax/dashboard_helper_behavior.rb index c2053ea64d..db1a5c7bfa 100644 --- a/app/helpers/hyrax/dashboard_helper_behavior.rb +++ b/app/helpers/hyrax/dashboard_helper_behavior.rb @@ -7,25 +7,40 @@ def on_the_dashboard? # @param user [User] # @param where [Hash] applied as the where clause when querying the Hyrax::WorkRelation - # + # @return [Integer] number of works matching the where that the user deposited # @see Hyrax::WorkRelation def number_of_works(user = current_user, where: { generic_type_sim: "Work" }) - where_clause = where.merge(DepositSearchBuilder.depositor_field => user.user_key) - Hyrax::WorkRelation.new.where(where_clause).count + field_pairs = field_pairs(user) + field_pairs.merge!(where) + count(Hyrax::SolrQueryBuilderService.construct_query(field_pairs)) rescue RSolr::Error::ConnectionRefused 'n/a' end + # @param user [User] + # @return [Integer] number of FileSets the user deposited def number_of_files(user = current_user) - ::FileSet.where(DepositSearchBuilder.depositor_field => user.user_key).count + count(Hyrax::SolrQueryBuilderService.construct_query_for_model(::FileSet, field_pairs(user))) rescue RSolr::Error::ConnectionRefused 'n/a' end + # @param user [User] + # @return [Integer] number of Collections the user created def number_of_collections(user = current_user) - ::Collection.where(DepositSearchBuilder.depositor_field => user.user_key).count + count(Hyrax::SolrQueryBuilderService.construct_query_for_model(::Collection, field_pairs(user))) rescue RSolr::Error::ConnectionRefused 'n/a' end + + private + + def field_pairs(user) + { DepositSearchBuilder.depositor_field => user.user_key } + end + + def count(query) + Hyrax::SolrService.count(query) + end end end