Permalink
Browse files

[api] reduce group request search to absolute required functionality …

…in 2.3 branch (master stays complete)
  • Loading branch information...
1 parent 98b25c1 commit 2979b60ee9c12b6d6c4d89f07c6c96d546cddd36 @adrianschroeter adrianschroeter committed Sep 12, 2012
Showing with 39 additions and 30 deletions.
  1. +4 −22 src/api/app/controllers/request_controller.rb
  2. +35 −8 src/api/app/models/group.rb
@@ -159,38 +159,20 @@ def index
inner_or = []
group = Group.get_by_title(params[:group])
- # find requests where group is maintainer in target project
- if roles.count == 0 or roles.include? "maintainer"
- names = group.involved_projects.map { |p| p.name }
- inner_or << "bs_request_actions.target_project in ('" + names.join("','") + "')"
-
- ## find request where group is maintainer in target package, except we have to project already
- group.involved_packages.each do |ip|
- inner_or << "(bs_request_actions.target_project='#{ip.db_project.name}' and bs_request_actions.target_package='#{ip.name}')"
- end
- end
-
if roles.count == 0 or roles.include? "reviewer"
review_states.each do |r|
# requests where the user is reviewer or own requests that are in review by someone else
- or_in_and = [ "reviews.by_group='#{group.title}'" ]
+ or_in_and = [ "review/@by_group='#{group.title}'" ]
- # find requests where group is maintainer in target project
- groupprojects = group.involved_projects.select("db_projects.name").map { |p| "'#{p.name}'" }
- or_in_and << "reviews.by_project in (#{groupprojects.join(',')})" unless groupprojects.blank?
- ## find request where user is maintainer in target package, except we have to project already
- group.involved_packages.select("name,db_project_id").includes(:db_project).each do |ip|
- or_in_and << "(reviews.by_project='#{ip.db_project.name}' and reviews.by_package='#{ip.name}')"
- end
-
- inner_or << "(reviews.state='#{r}' and (#{or_in_and.join(" or ")}))"
+ inner_or << "(review/@state='#{r}' and (#{or_in_and.join(" or ")}))"
end
end
unless inner_or.empty?
- rel = rel.where(inner_or.join(" or "))
+ str = "(" + inner_or.join(" or ") + ")"
+ outer_and << str
end
end
@@ -71,31 +71,58 @@ def render_axml
def involved_projects_ids
# just for maintainer for now.
- role = Role.rolecache["maintainer"]
+ role = Role.find_by_title "maintainer"
- ### all projects where user is maintainer
- projects = ProjectGroupRoleRelationship.where(bs_group_id: id, role_id: role.id).select(:db_project_id).all.map {|ur| ur.db_project_id }
+ ### all projects where group is maintainer
+ # ur is the target user role relationship
+ sql =
+ "SELECT prj.id
+ FROM db_projects prj
+ LEFT JOIN project_group_role_relationships ur ON prj.id = ur.db_project_id
+ WHERE ur.bs_group_id = #{id} and ur.role_id = #{role.id}"
+ projects = ActiveRecord::Base.connection.select_values sql
- projects.uniq
+ projects += ActiveRecord::Base.connection.select_values sql
+ projects.uniq.map {|p| p.to_i }
end
protected :involved_projects_ids
def involved_projects
+ projects = involved_projects_ids
+ return [] if projects.empty?
# now filter the projects that are not visible
- return DbProject.where(id: involved_projects_ids)
+ return DbProject.find_by_sql("SELECT distinct prj.* FROM db_projects prj
+ LEFT JOIN flags f on f.db_project_id = prj.id
+ LEFT JOIN project_group_role_relationships aur ON aur.db_project_id = prj.id
+ where prj.id in (#{projects.join(',')})
+ and (f.flag is null or f.flag != 'access' or aur.id = #{User.currentID})")
end
# lists packages maintained by this user and are not in maintained projects
def involved_packages
# just for maintainer for now.
- role = Role.rolecache["maintainer"]
+ role = Role.find_by_title "maintainer"
projects = involved_projects_ids
projects << -1 if projects.empty?
# all packages where group is maintainer
- packages = PackageGroupRoleRelationship.where(bs_group_id: id, role_id: role.id).joins(:db_package).where("db_packages.db_project_id not in (?)", projects).select(:db_package_id).all.map {|ur| ur.db_package_id}
+ sql =<<-END_SQL
+ SELECT pkg.id
+ FROM db_packages pkg
+ LEFT JOIN db_projects prj ON prj.id = pkg.db_project_id
+ LEFT JOIN package_group_role_relationships ur ON pkg.id = ur.db_package_id
+ WHERE ur.bs_user_id = #{id} and ur.role_id = #{role.id} and
+ prj.id not in (#{projects.join(',')})
+ END_SQL
+ packages = ActiveRecord::Base.connection.select_values sql
- return DbPackage.where(id: packages).where("db_project_id not in (?)", projects)
+ return [] if packages.empty?
+ return DbPackage.find_by_sql("SELECT distinct pkg.* FROM db_packages pkg
+ LEFT JOIN flags f on f.db_project_id = pkg.db_project_id
+ LEFT JOIN project_user_role_relationships aur ON aur.db_project_id = pkg.db_project_id
+ where pkg.id in (#{packages.join(',')})
+ and (f.flag is null or f.flag != 'access' or aur.id = #{User.currentID})")
+
end
end

0 comments on commit 2979b60

Please sign in to comment.