Skip to content

Commit

Permalink
Remove architecture and repository relationship from project and package
Browse files Browse the repository at this point in the history
The were only supporting the rather crude get_flags, which is only
used in one controller action, which queries architecture and
repositories anyway - so wasteful
  • Loading branch information
coolo committed Dec 20, 2018
1 parent c5d34de commit 7f41c93
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/api/app/controllers/webui/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class Webui::RepositoriesController < Webui::WebuiController
# GET project/repositories/:project
def index
return if switch_to_webui2
@build = @main_object.get_flags('build')
@debuginfo = @main_object.get_flags('debuginfo')
@publish = @main_object.get_flags('publish')
@useforbuild = @main_object.get_flags('useforbuild')
@architectures = @main_object.architectures.reorder('name').distinct
@architectures = Architecture.where(id: @project.repository_architectures.select(:architecture_id)).order(:name)
@repositories = @project.repositories.includes(:path_elements, :download_repositories)
repository_names = @repositories.pluck(:name)
@build = @main_object.get_flags('build', repository_names, @architectures)
@debuginfo = @main_object.get_flags('debuginfo', repository_names, @architectures)
@publish = @main_object.get_flags('publish', repository_names, @architectures)
@useforbuild = @main_object.get_flags('useforbuild', repository_names, @architectures)

@user_can_set_flags = policy(@project).update?

@repositories = @project.repositories.includes(:path_elements, :download_repositories)
end

# GET project/add_repository/:project
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui2/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def webui2_index

@user_can_set_flags = policy(@project).update?

@architectures = @project.architectures.reorder('name')
@architectures = Architecture.where(id: @project.repository_architectures.select(:architecture_id)).reorder('name').distinct
@repositories = @project.repositories.includes(:path_elements, :download_repositories)
end

Expand Down
6 changes: 3 additions & 3 deletions src/api/app/mixins/get_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module GetFlags
# The arrays contain Flag objects of type, sorted by architecture.
# Like:
# {all: [Flag, Flag-i586, Flag-x86_64], 13.2: [Flag, Flag-i585, Flag-x86_64]}
def get_flags(flag_type)
def get_flags(flag_type, repository_names, architectures)
the_flags = {}

# [nil] is a placeholder for "all" repositories
[nil].concat(repositories.pluck(:name)).each do |repository|
[nil].concat(repository_names).each do |repository|
the_flags[repository] = []
# [nil] is a placeholder for "all" architectures
[nil].concat(architectures.reorder('name').distinct).each do |architecture|
[nil].concat(architectures).each do |architecture|
architecture_id = architecture ? architecture.id : nil
flag = flags.where(flag: flag_type).where(repo: repository).where(architecture_id: architecture_id).first
# If there is no flag create a temporary one.
Expand Down
2 changes: 0 additions & 2 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class Package < ApplicationRecord

belongs_to :project, inverse_of: :packages
delegate :name, to: :project, prefix: true
delegate :repositories, to: :project
delegate :architectures, to: :project

attr_reader :commit_opts
attr_writer :commit_opts
Expand Down
1 change: 0 additions & 1 deletion src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def autocomplete(search)
has_many :path_elements, through: :repositories
has_many :linked_repositories, through: :path_elements, source: :link, foreign_key: :repository_id
has_many :repository_architectures, -> { order('position') }, through: :repositories
has_many :architectures, -> { order('position').distinct }, through: :repository_architectures

has_many :messages, as: :db_object, dependent: :delete_all
has_many :watched_projects, dependent: :destroy, inverse_of: :project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
get :index, params: { project: apache_project }
end

it { expect(assigns(:build).to_s).to eq(apache_project.get_flags('build').to_s) }
it { expect(assigns(:debuginfo).to_s).to eq(apache_project.get_flags('debuginfo').to_s) }
it { expect(assigns(:publish).to_s).to eq(apache_project.get_flags('publish').to_s) }
it { expect(assigns(:useforbuild).to_s).to eq(apache_project.get_flags('useforbuild').to_s) }
it { expect(assigns(:architectures)).to eq(apache_project.architectures.uniq) }
it { expect(assigns(:architectures)).to be_empty }
end

describe 'GET #state' do
Expand Down

0 comments on commit 7f41c93

Please sign in to comment.