class ActiveFedora::Indexing::DescendantFetcher
ActiveFedora::Indexing::DescendantFetcher.default_priority_models = []
Change the default prioritized hasModel names:
Hydra::AccessControls permissions) objects FIRST.
#=> array including self uri and descendent uris with “prioritized” (by default)
DescendantFetcher.new(ActiveFedora.fedora.base_uri).descendent_and_self_uris
but you can alter the prioritized model name list, or set it to the empty array.
And so by default, the prioritized class names are the ones form Hydra::AccessControls,
index ‘permissions’ objects before other objects to have the solr indexing work right.
with certain hasModel models. This feature is used in some samvera apps that need to
that will be first in the returned list. These prioritized URIs belong to objects
The DescendantFetcher is also capable of partitioning the URIs into “priority” URIs
object from the repo.
This is a slow and non-performant thing to do, we need to fetch every single
Finds all descendent URIs of a given repo URI (usually the base URI).
def add_self_to_partitioned_uris
def add_self_to_partitioned_uris rdf_graph.query({ predicate: HAS_MODEL_PREDICATE }).each_object do |model| next unless model.literal? partitioned_uris[model.to_s] ||= [] partitioned_uris[model.to_s] << rdf_resource.subject end end
def descendant_and_self_uris
-
(Array
- uris starting with priority models)
def descendant_and_self_uris partitioned = descendant_and_self_uris_partitioned partitioned[:priority] + partitioned[:other] end
def descendant_and_self_uris_partitioned
-
(Hash
- uris sorted into :priority and :other>)
def descendant_and_self_uris_partitioned model_partitioned = descendant_and_self_uris_partitioned_by_model { priority: model_partitioned.slice(*priority_models).values.flatten, other: model_partitioned.slice(*(model_partitioned.keys - priority_models)).values.flatten } end
def descendant_and_self_uris_partitioned_by_model
-
(Hash
- uris sorted by model names>)
def descendant_and_self_uris_partitioned_by_model # GET could be slow if it's a big resource, we're using HEAD to avoid this problem, # but this causes more requests to Fedora. return partitioned_uris unless rdf_resource.head.rdf_source? add_self_to_partitioned_uris unless @exclude_self rdf_graph.query({ predicate: ::RDF::Vocab::LDP.contains }).each_object do |uri| descendant_uri = uri.to_s self.class.new( descendant_uri, priority_models: priority_models ).descendant_and_self_uris_partitioned_by_model.tap do |descendant_partitioned| descendant_partitioned.keys.each do |k| partitioned_uris[k] ||= [] partitioned_uris[k].concat descendant_partitioned[k] end end end partitioned_uris end
def initialize(uri,
def initialize(uri, priority_models: self.class.default_priority_models, exclude_self: false) @uri = uri @priority_models = priority_models @exclude_self = exclude_self end
def partitioned_uris
def partitioned_uris @partitioned_uris ||= {} end
def rdf_graph
def rdf_graph @rdf_graph ||= rdf_resource.graph end
def rdf_resource
def rdf_resource @rdf_resource ||= Ldp::Resource::RdfSource.new(ActiveFedora.fedora.build_ntriples_connection, uri) end