Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate FindObjectsViaSolrService replaced by SolrQueryService#get_objects #5023

Merged
merged 3 commits into from
Jul 14, 2021

Conversation

elrayle
Copy link
Contributor

@elrayle elrayle commented Jul 13, 2021

Use SolrQueryService#get_objects instead of FindObjectsViaSolrService when objects are required. If solr documents are sufficient, then just use SolrQueryService#get.

By using SolrQueryService, this allows for the construction of more complex queries even when objects are being returned.

Also updated MultipleMembershipChecker to use SolrQueryService instead of FindObjectViaSolrService. This was the only use of FindObjectViaSolrService.

Related to: Issue #3820 which is replacing ActiveFedora::Base.where calls.

@samvera/hyrax-code-reviewers

Copy link
Contributor

@no-reply no-reply left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

one small doc suggestion, and a question are in inline comments

app/services/hyrax/find_objects_via_solr_service.rb Outdated Show resolved Hide resolved
def get_objects(use_valkyrie: Hyrax.config.use_valkyrie?)
ids = get_ids
return ids.map { |id| ActiveFedora::Base.find(id) }.to_a unless use_valkyrie
query_service.find_many_by_ids(ids: ids).to_a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the #to_a desirable, or could this return an Enumerator?

it seems like avoiding loading data that won't be used is attractive.

Copy link
Contributor Author

@elrayle elrayle Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I'll remove it and see if everything continues to work. I used to_a because the deprecated method used it. I can't remember the original reason for using to_a.

elrayle and others added 2 commits July 14, 2021 12:06
…objects

Use SolrQueryService#get_objects instead of FindObjectsViaSolrService when objects are required.  If solr documents are sufficient, then just use SolrQueryService#get.

By using SolrQueryService, this allows for the construction of more complex queries even when objects are being returned.

Update MultipleMembershipChecker to use SolrQueryService instead of FindObjectViaSolrService.
Co-authored-by: tamsin johnson <tomjohnson@ucsb.edu>
solr_query_builder.new
.with_model(model: model)
.with_field_pairs(field_pairs: field_pairs, join_with: join_with, type: type)
.get_objects(use_valkyrie: use_valkyrie).to_a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindObjectViaSolrService #find_for_model_by_field_pairs needs to continue to return an Array for backward compatibility.

This method is no longer used in any Hyrax code.

@@ -55,9 +55,12 @@ def single_membership_collections(collection_ids)

field_pairs = {
:id => collection_ids,
Hyrax.config.collection_type_index_field.to_sym => collection_type_gids_that_disallow_multiple_membership
Hyrax.config.collection_type_index_field.to_sym => collection_type_gids_that_disallow_multiple_membership&.map(&:to_s)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map to strings is required to turn GlobalIDs into string IDs. I'm not sure why this worked before. It definitely does not work with the SolrQueryService.

def get_objects(use_valkyrie: Hyrax.config.use_valkyrie?)
ids = get_ids
return ids.map { |id| ActiveFedora::Base.find(id) } unless use_valkyrie
query_service.find_many_by_ids(ids: ids)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed .to_a on the returned result to maintain the Enumerable.

Hyrax::SolrQueryService.new
.with_model(model: ::Collection)
.with_field_pairs(field_pairs: field_pairs, join_with: ' OR ')
.get_objects(use_valkyrie: true).to_a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result is required to be an Array because later it is used in...

collections_to_check |= single_membership_collections(item.member_of_collection_ids)

where the result is collections_to_check.

@no-reply no-reply merged commit 1aa7bdf into main Jul 14, 2021
@no-reply no-reply deleted the get_objects branch July 14, 2021 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants