Skip to content

Commit

Permalink
Merge pull request #6342 from coolo/rename_status_reports
Browse files Browse the repository at this point in the history
Rename relevant_status_reports to just status_reports
  • Loading branch information
ChrisBr committed Nov 26, 2018
2 parents 28e6374 + 26ca5c0 commit 9f3df39
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 62 deletions.
11 changes: 2 additions & 9 deletions src/api/app/helpers/webui/staging/workflow_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@ def review_progress(staging_project)
end

def testing_progress(staging_project)
notdone = allchecks = 0

# Note: The status_reports are defined via a has many through relation. Since within the
# status report context the bs request relation is polymorphic, we have to call
# includes with the polymorphic name ('checkable').
staging_project.status_reports.includes(:checkable).each do |report|
notdone += report.checks.where(state: 'pending').size
allchecks += report.checks.size + report.missing_checks.size
end
notdone = staging_project.checks.pending.size
allchecks = staging_project.checks.size + staging_project.missing_checks.size

return 100 if allchecks == 0
100 - notdone * 100 / allchecks
Expand Down
34 changes: 5 additions & 29 deletions src/api/app/models/obs_factory/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def self.find(distribution, id)
# @return [String] description of the Project object
delegate :description, to: :project

delegate :checks, to: :project
delegate :missing_checks, to: :project

# Checks if the project is adi staging project
#
# @return [Boolean] true if the project is adi staging project
Expand Down Expand Up @@ -192,9 +195,9 @@ def build_state
end

def check_state
if missing_checks.present? || checks.any?(&:pending?)
if missing_checks.present? || checks.pending.exists?
:testing
elsif checks.any?(&:failed?)
elsif checks.failed.exists?
:failed
else
:acceptable
Expand Down Expand Up @@ -228,35 +231,8 @@ def overall_state
@state
end

def checks
fetch_status if @checks.nil?
@checks
end

def missing_checks
fetch_status if @missing_checks.nil?
@missing_checks
end

protected

def fetch_status
@checks = []
@missing_checks = []
repositories.each do |repo|
add_status(repo)
repo.repository_architectures.each do |repo_arch|
add_status(repo_arch)
end
end
end

def add_status(checkable)
status = checkable.current_status_report
@missing_checks += status.missing_checks
@checks += status.checks
end

# Used internally to calculate #broken_packages and #building_repositories
def set_buildinfo
buildresult = Xmlhash.parse(Backend::Api::BuildResults::Status.failed_results(name))
Expand Down
30 changes: 30 additions & 0 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,14 @@ def dashboard
packages.find_by(name: 'dashboard')
end

def checks
Status::Check.where(status_report: combined_status_reports)
end

def missing_checks
@missing_checks ||= calculate_missing_checks
end

private

def discard_cache
Expand Down Expand Up @@ -1744,6 +1752,28 @@ def has_local_distribution(project_name, repository)
linked_repository.name == repository
end
end

def status_reports(checkables)
status_reports = Status::Report.where(checkable: checkables)
result = {}
status_reports.where(uuid: checkables.map(&:build_id)).find_each do |report|
result[report.checkable] = report
end

checkables.each do |checkable|
result[checkable] ||= Status::Report.new(checkable: checkable)
end

result.values
end

def combined_status_reports
@combined_status_reports ||= status_reports(repositories) | status_reports(repository_architectures)
end

def calculate_missing_checks
combined_status_reports.map(&:missing_checks).flatten
end
end
# rubocop:enable Metrics/ClassLength

Expand Down
22 changes: 2 additions & 20 deletions src/api/app/models/staging/staging_project.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module Staging
class StagingProject < Project
has_many :staged_requests, class_name: 'BsRequest', foreign_key: :staging_project_id, dependent: :nullify
has_many :status_reports_for_repositories, source: :status_reports, through: :repositories, inverse_of: :checkable
has_many :status_reports_for_architectures, source: :status_reports, through: :repository_architectures, inverse_of: :checkable

belongs_to :staging_workflow, class_name: 'Staging::Workflow'

default_scope { where.not(staging_workflow: nil) }
Expand Down Expand Up @@ -98,14 +95,6 @@ def unassign_managers_group(managers)
relationships.find_by(group: managers, role: role).try(:destroy!)
end

def checks
@checks ||= Status::Check.where(status_reports_id: relevant_status_reports_for_repositories | relevant_status_reports_for_architectures)
end

def missing_checks
@missing_checks ||= (relevant_status_reports_for_repositories + relevant_status_reports_for_architectures).map(&:missing_checks).flatten
end

private

def cache_problems
Expand Down Expand Up @@ -139,7 +128,8 @@ def build_state
:acceptable
end

def relevant_status_reports(checkables, status_reports)
def status_reports(checkables)
status_reports = Status::Report.where(checkable: checkables)
result = {}
status_reports.where(uuid: checkables.map(&:build_id)).find_each do |report|
result[report.checkable] = report
Expand All @@ -152,14 +142,6 @@ def relevant_status_reports(checkables, status_reports)
result.values
end

def relevant_status_reports_for_repositories
@relevant_status_reports_for_repositories ||= relevant_status_reports(repositories, status_reports_for_repositories)
end

def relevant_status_reports_for_architectures
@relevant_status_reports_for_architectures ||= relevant_status_reports(repository_architectures, status_reports_for_architectures)
end

def check_state
return :testing if missing_checks.present? || checks.pending.exists?
return :failed if checks.failed.exists?
Expand Down
4 changes: 0 additions & 4 deletions src/api/app/models/status/checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ module Status::Checkable
serialize :required_checks, Array
has_many :status_reports, as: :checkable, class_name: 'Status::Report', dependent: :destroy
end

def current_status_report
status_reports.find_or_initialize_by(uuid: build_id)
end
end

0 comments on commit 9f3df39

Please sign in to comment.