]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4535 Improve profile list WS
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Dec 2013 08:26:16 +0000 (09:26 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 18 Dec 2013 08:26:16 +0000 (09:26 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb

index 03b87f2e60401f861bfd4dab87e3f141f8e7068b..f60f6e03e7c4335edba6a505a721ca84518de86d 100644 (file)
@@ -34,17 +34,22 @@ class Api::ProfilesController < Api::ApiController
     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}
@@ -52,7 +57,7 @@ class Api::ProfilesController < Api::ApiController
       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]