Skip to content

Commit

Permalink
Merge branch 'main' into double_combo
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpierce authored Jun 21, 2024
2 parents 6447872 + 72e570a commit 66cae2b
Show file tree
Hide file tree
Showing 25 changed files with 318 additions and 284 deletions.
40 changes: 24 additions & 16 deletions .github/workflows/build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ jobs:
build:
needs: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ci_test_app: [dassie,koppie]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -51,46 +55,53 @@ jobs:
uses: docker/build-push-action@v5
with:
build-args: |
APP_PATH=.koppie
APP_PATH=.${{ matrix.ci_test_app }}
cache-from: type=gha
cache-to: type=gha, mode=max
context: .
target: hyrax-engine-dev
tags: samvera/koppie:latest,samvera/koppie:${{ github.sha }}
outputs: type=docker,dest=/tmp/koppie-${{ github.sha }}.tar
tags: samvera/${{ matrix.ci_test_app }}:latest,samvera/${{ matrix.ci_test_app }}:${{ github.sha }}
outputs: type=docker,dest=/tmp/${{ matrix.ci_test_app }}-${{ github.sha }}.tar
- name: Upload built image artifact
uses: actions/upload-artifact@v4
with:
name: koppie-image
path: /tmp/koppie-${{ github.sha }}.tar
name: ${{ matrix.ci_test_app }}-image
path: /tmp/${{ matrix.ci_test_app }}-${{ github.sha }}.tar

test:
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ci_test_app: [dassie,koppie]
ci_node_total: [8]
ci_node_index: [0,1,2,3,4,5,6,7]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup tmate debug session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
with:
limit-access-to-actor: true
detached: true
- name: Download built image artifact
uses: actions/download-artifact@v4
with:
name: koppie-image
name: ${{ matrix.ci_test_app }}-image
path: /tmp
- name: Start containers
run: |
docker load --input /tmp/koppie-${{ github.sha }}.tar
docker load --input /tmp/${{ matrix.ci_test_app }}-${{ github.sha }}.tar
docker image ls -a
docker compose -f docker-compose-koppie.yml up -d --quiet-pull --pull missing --no-build
docker compose -f docker-compose-${{ matrix.ci_test_app }}.yml up -d --quiet-pull --pull missing --no-build
- name: RSpec
env:
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: >-
docker compose -f docker-compose-koppie.yml exec -T -w /app/samvera/hyrax-engine web sh -c
docker compose -f docker-compose-${{ matrix.ci_test_app }}.yml exec -T -w /app/samvera/hyrax-engine web sh -c
"bundle install && yarn install && rspec_booster --job ${{ matrix.ci_node_index }}/${{ matrix.ci_node_total }}"
- name: Capture Container Logs
if: always()
Expand All @@ -100,21 +111,17 @@ jobs:
- name: Move Test Files
if: always()
env:
CI_TEST_APP: ${{ matrix.ci_test_app }}
CI_NODE_TOTAL: ${{ matrix.ci_node_total }}
CI_NODE_INDEX: ${{ matrix.ci_node_index }}
run: >-
mv rspec.xml rspec-${CI_NODE_INDEX}.xml
mv rspec.xml rspec-${CI_TEST_APP}-${CI_NODE_INDEX}.xml
- name: Archive spec reports
uses: actions/upload-artifact@v4
if: always()
with:
name: spec-reports-${{ matrix.ci_node_index }}
name: spec-reports-${{ matrix.ci_test_app }}-${{ matrix.ci_node_index }}
path: '**/rspec*.xml'
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: failure()
with:
limit-access-to-actor: true

report:
needs: test
Expand All @@ -129,6 +136,7 @@ jobs:
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: "*report*"
- name: Publish Test Report
uses: EnricoMi/publish-unit-test-result-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG ALPINE_VERSION=3.19
ARG RUBY_VERSION=3.2.3
ARG RUBY_VERSION=3.2.4

FROM ruby:$RUBY_VERSION-alpine$ALPINE_VERSION as hyrax-base

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/hyrax/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def add_breadcrumb_for_action
when 'file'
add_breadcrumb I18n.t("hyrax.file_set.browse_view"), main_app.hyrax_file_set_path(params["id"])
when 'work'
add_breadcrumb @work.to_s, main_app.polymorphic_path(@work)
add_breadcrumb @work.title.first, main_app.polymorphic_path(@work)
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/hyrax/file_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ def extracted_file?
pcdm_use.include?(Use::EXTRACTED_TEXT)
end

##
# Filters out uses not recognized by Hyrax (e.g. http://fedora.info/definitions/v4/repository#Binary)
# @return [Array]
def filtered_pcdm_use
pcdm_use.select { |use| Use.use_list.include?(use) }
end

##
# @return [String]
def to_rdf_representation
Expand Down
3 changes: 1 addition & 2 deletions app/models/hyrax/file_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def extensions_and_mime_types
next unless fm.original_filename
extension = File.extname(fm.original_filename)
next if extension.empty?

use = fm.pcdm_use.first.to_s.split("#").last
use = fm.filtered_pcdm_use.first.to_s.split("#").last
name = use == 'OriginalFile' ? nil : File.basename(fm.original_filename, extension).split('-').last
arr << {
id: fm.id.to_s,
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/hyrax/file_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def to_flot
private

def downloads
to_flots(FileDownloadStat.statistics(model, created, user_id))
@downloads ||= to_flots(FileDownloadStat.statistics(model, created, user_id))
end

def pageviews
to_flots(FileViewStat.statistics(model, created, user_id))
@pageviews ||= to_flots(FileViewStat.statistics(model, created, user_id))
end
end
end
2 changes: 1 addition & 1 deletion app/presenters/hyrax/stats_usage_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def to_flots(stats)
def date_for_analytics
earliest = Hyrax.config.analytic_start_date
date_uploaded = string_to_date(model.date_uploaded)
date_analytics = date_uploaded ? date_uploaded : model.create_date
date_analytics = date_uploaded ? date_uploaded : (model.create_date || model.created_at)
return date_analytics if earliest.blank?
earliest > date_analytics ? earliest : date_analytics
end
Expand Down
7 changes: 5 additions & 2 deletions app/presenters/hyrax/work_usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ module Hyrax
# and prepares it for visualization in /app/views/stats/work.html.erb
class WorkUsage < StatsUsagePresenter
def initialize(id)
self.model = Hyrax::WorkRelation.new.find(id)
self.model = Hyrax.query_service.find_by(id: id)
end

alias work model
delegate :to_s, to: :model

def to_s
model.title.first
end

def total_pageviews
pageviews.reduce(0) { |total, result| total + result[1].to_i }
Expand Down
9 changes: 7 additions & 2 deletions app/search_builders/hyrax/valkyrie_abstract_type_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ def count
Hyrax.query_service.custom_queries.find_count_by(models: allowable_types)
end

def where(hash)
Hyrax.query_service.find_references_by(resource: hash.values.first, property: hash.keys.first)
def where(hash_or_string)
case hash_or_string
when String
Hyrax::SolrService.query(hash_or_string)
else
Hyrax.query_service.find_references_by(resource: hash_or_string.values.first, property: hash_or_string.keys.first)
end
end

def ==(other)
Expand Down
16 changes: 15 additions & 1 deletion app/services/hyrax/solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def select_path
end

delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post,
:query, :query_result, :delete_by_query, :search_by_id, :wipe!, to: :new
:query, :query_result, :query_in_batches, :delete_by_query, :search_by_id, :wipe!, to: :new
end

# Wraps rsolr get
Expand Down Expand Up @@ -111,6 +111,20 @@ def query(query, **args)
end
end

def query_in_batches(query, **args)
args[:rows] ||= 500
args[:start] ||= 0
loop do
result = query_result(query, **args)
break if result['response']['docs'].blank? || result['response']['numFound'] <= args[:start]
result['response']['docs'].select do |doc|
yield ::SolrHit.new(doc)
nil
end
args[:start] += args[:rows]
end
end

# Wraps rsolr :delete_by_query
def delete_by_query(query, **args)
connection.delete_by_query(query, params: args)
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/statistics/query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def build_date_query(start_datetime, end_datetime)
delegate :count, to: :relation

def relation
Hyrax::WorkRelation.new
Hyrax.config.disable_wings ? Hyrax::ValkyrieWorkRelation.new : Hyrax::WorkRelation.new
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/statistics/works/over_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def points
private

def relation
Hyrax::WorkRelation.new
Hyrax.config.disable_wings ? Hyrax::ValkyrieWorkRelation.new : Hyrax::WorkRelation.new
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/services/hyrax/user_stat_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def process_files(stats, user, start_date)

def process_works(stats, user, start_date)
work_ids_for_user(user).each do |work_id|
work = Hyrax::WorkRelation.new.find(work_id)
work = Hyrax.query_service.find_by(id: work_id)
work_stats = extract_stats_for(object: work, from: WorkViewStat, start_date: start_date, user: user)
stats = tally_results(work_stats, :work_views, stats) if work_stats.present?
delay
Expand Down Expand Up @@ -94,7 +94,7 @@ def date_since_last_cache(user)
if last_cached_stat
last_cached_stat.date + 1.day
else
Hyrax.config.analytic_start_date
Hyrax.config.analytic_start_date || 1.week.ago
end
end

Expand All @@ -108,8 +108,8 @@ def file_ids_for_user(user)

def work_ids_for_user(user)
ids = []
Hyrax::WorkRelation.new.search_in_batches("#{depositor_field}:\"#{user.user_key}\"", fl: "id") do |group|
ids.concat group.map { |doc| doc["id"] }
Hyrax::SolrService.query_in_batches("#{depositor_field}:\"#{user.user_key}\"", fl: "id") do |hit|
ids << hit.id
end
ids
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/hyrax/work_query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Hyrax
# Responsible for retrieving information based on the given work.
#
# @see ProxyDepositRequest
# @see Hyrax::WorkRelation
# @see Hyrax::VaklyrieWorkRelation
# @see SolrDocument
# @see Hyrax::SolrService
# @see ActiveFedora::SolrQueryBuilder
Expand All @@ -20,7 +20,7 @@ def initialize(id:, work_relation: default_work_relation)
private

def default_work_relation
Hyrax::WorkRelation.new
Hyrax.config.disable_wings ? Hyrax::ValkyrieWorkRelation.new : Hyrax::WorkRelation.new
end

public
Expand Down
Loading

0 comments on commit 66cae2b

Please sign in to comment.