language = params[:language]
project_key = params[:project]
+ default_profile_by_language = {}
if project_key.present?
project = Project.by_key(project_key)
not_found('Unknown project') unless project
profiles = Internal.quality_profiles.profiles(project.id).to_a
if language.present?
profile = profiles.find {|profile| profile.language == language} if profiles
- # Return default if null
- profiles = [profile] if profile
- profiles = [Internal.quality_profiles.defaultProfile(language.to_s)] unless profile
+ # Return default profile if the project is not associate to a profile
+ profile = Internal.quality_profiles.defaultProfile(language.to_s) unless profile
else
- profiles = [Internal.quality_profiles.defaultProfile(project.language.to_s)] if profiles.empty?
+ profile = Internal.quality_profiles.defaultProfile(project.language.to_s) if profiles.empty?
+ end
+ if profile
+ # Populate default profile by language to not execute twice the SQL to get default profile
+ profiles = [profile]
+ default_profile_by_language[profile.language] = profile
end
elsif language.present?
profiles = Internal.quality_profiles.allProfiles().select {|profile| profile.language == language}
profiles = Internal.quality_profiles.allProfiles().to_a
end
- default_profile_by_language = {}
+ # Populate the map of default profile by language by searching for all profiles languages
profiles.each do |p|
lang = p.language
unless default_profile_by_language[lang]