Module: Sufia::CollectionBehavior
- Extended by:
- ActiveSupport::Concern
- Includes:
- Hydra::Collection, GenericFile::Permissions, ModelMethods, Noid
- Included in:
- Collection
- Defined in:
- app/models/concerns/sufia/collection_behavior.rb
Instance Method Summary collapse
-
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to hit Fedora.
Methods included from Permissions::Readable
#private?, #public?, #registered?
Methods included from Permissions::Writable
#clear_permissions!, #paranoid_edit_permissions, #paranoid_permissions
Methods included from Noid
Methods included from ModelMethods
Instance Method Details
#bytes ⇒ Fixnum
Compute the sum of each file in the collection using Solr to avoid having to hit Fedora
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/concerns/sufia/collection_behavior.rb', line 18 def bytes rows = members.count return 0 if rows == 0 raise "Collection must be saved to query for bytes" if new_record? query = ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: file_model) args = { fq: "{!join from=hasCollectionMember_ssim to=id}id:#{id}", fl: "id, #{file_size_field}", rows: rows } files = ActiveFedora::SolrService.query(query, args) files.reduce(0) { |sum, f| sum + f[file_size_field].to_i } end |