diff options
author | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-03-26 19:06:01 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-03-26 19:06:01 +0300 |
commit | 4fd30599548ba4918cc9c5a4af4abb0f1bc79fe3 (patch) | |
tree | 534c393ae2a9d36f7b080b19834cfa86cc00e5ff /app | |
parent | 633587b744eb247a0b96f4949b48dd4324d5db23 (diff) | |
parent | 4acf107b1e09e96f9c1f0d20b024540229e76e55 (diff) |
Merge branch 'security-id-potential-denial-languages-11-9' into '11-9-stable'
Return cached languages if they've been detected before
See merge request gitlab/gitlabhq!3029
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/graphs_controller.rb | 8 | ||||
-rw-r--r-- | app/services/projects/detect_repository_languages_service.rb | 10 | ||||
-rw-r--r-- | app/services/projects/repository_languages_service.rb | 24 |
3 files changed, 35 insertions, 7 deletions
diff --git a/app/controllers/projects/graphs_controller.rb b/app/controllers/projects/graphs_controller.rb index c80fce513f6..67d3f49af18 100644 --- a/app/controllers/projects/graphs_controller.rb +++ b/app/controllers/projects/graphs_controller.rb @@ -46,12 +46,8 @@ class Projects::GraphsController < Projects::ApplicationController def get_languages @languages = - if @project.repository_languages.present? - @project.repository_languages.map do |lang| - { value: lang.share, label: lang.name, color: lang.color, highlight: lang.color } - end - else - @project.repository.languages + ::Projects::RepositoryLanguagesService.new(@project, current_user).execute.map do |lang| + { value: lang.share, label: lang.name, color: lang.color, highlight: lang.color } end end diff --git a/app/services/projects/detect_repository_languages_service.rb b/app/services/projects/detect_repository_languages_service.rb index 4a837a4fb6a..b020e4d9088 100644 --- a/app/services/projects/detect_repository_languages_service.rb +++ b/app/services/projects/detect_repository_languages_service.rb @@ -2,7 +2,7 @@ module Projects class DetectRepositoryLanguagesService < BaseService - attr_reader :detected_repository_languages, :programming_languages + attr_reader :programming_languages # rubocop: disable CodeReuse/ActiveRecord def execute @@ -25,6 +25,8 @@ module Projects RepositoryLanguage.table_name, detection.insertions(matching_programming_languages) ) + + set_detected_repository_languages end project.repository_languages.reload @@ -56,5 +58,11 @@ module Projects retry end # rubocop: enable CodeReuse/ActiveRecord + + def set_detected_repository_languages + return if project.detected_repository_languages? + + project.update_column(:detected_repository_languages, true) + end end end diff --git a/app/services/projects/repository_languages_service.rb b/app/services/projects/repository_languages_service.rb new file mode 100644 index 00000000000..e75851c7da4 --- /dev/null +++ b/app/services/projects/repository_languages_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Projects + class RepositoryLanguagesService < BaseService + def execute + perform_language_detection unless project.detected_repository_languages? + persisted_repository_languages + end + + private + + def perform_language_detection + if persisted_repository_languages.blank? + ::DetectRepositoryLanguagesWorker.perform_async(project.id, current_user.id) + else + project.update_column(:detected_repository_languages, true) + end + end + + def persisted_repository_languages + project.repository_languages + end + end +end |