Skip to content

Commit

Permalink
replace AF.where method using solr to count
Browse files Browse the repository at this point in the history
Objects are not needed to count the number of results.  Only using solr to count.

rc
  • Loading branch information
elrayle committed May 6, 2021
1 parent 6adbe21 commit baf0a21
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions app/helpers/hyrax/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit baf0a21

Please sign in to comment.