diff options
author | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-04-02 10:48:28 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-04-02 10:48:28 +0300 |
commit | b122be5ed55e3898196fb21e47fff40eb7dd6e0c (patch) | |
tree | 709d2763de4f693086b1f0cbe8848df3a8ed5509 /app/services | |
parent | 02dcecdb5f51f6988ede356d0d245d6cd7745520 (diff) | |
parent | 732f892db308863f2a2db736949c94ae9d613678 (diff) |
Merge branch 'security-id-potential-denial-languages' into 'master'
Return cached languages if they've been detected before
See merge request gitlab/gitlabhq!2998
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/projects/detect_repository_languages_service.rb | 10 | ||||
-rw-r--r-- | app/services/projects/repository_languages_service.rb | 24 |
2 files changed, 33 insertions, 1 deletions
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 |