diff options
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r-- | app/models/repository.rb | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index ee1bea0e8d2..3413b3e3424 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -48,22 +48,19 @@ class Repository # For example, for entry `:commit_count` there's a method called `commit_count` which # stores its data in the `commit_count` cache key. CACHED_METHODS = %i(size commit_count readme_path contribution_guide - changelog license_blob license_key gitignore + changelog license_blob license_licensee license_gitaly gitignore gitlab_ci_yml branch_names tag_names branch_count tag_count avatar exists? root_ref merged_branch_names has_visible_content? issue_template_names_hash merge_request_template_names_hash user_defined_metrics_dashboard_paths xcode_project? has_ambiguous_refs?).freeze - # Methods that use cache_method but only memoize the value - MEMOIZED_CACHED_METHODS = %i(license).freeze - # Certain method caches should be refreshed when certain types of files are # changed. This Hash maps file types (as returned by Gitlab::FileDetector) to # the corresponding methods to call for refreshing caches. METHOD_CACHES_FOR_FILE_TYPES = { readme: %i(readme_path), changelog: :changelog, - license: %i(license_blob license_key license), + license: %i(license_blob license_licensee license_gitaly), contributing: :contribution_guide, gitignore: :gitignore, gitlab_ci: :gitlab_ci_yml, @@ -650,25 +647,30 @@ class Repository cache_method :license_blob def license_key - return unless exists? - - raw_repository.license_short_name + license&.key end - cache_method :license_key def license - return unless license_key + if Feature.enabled?(:license_from_gitaly) + license_gitaly + else + license_licensee + end + end - licensee_object = Licensee::License.new(license_key) + def license_licensee + return unless exists? - return if licensee_object.name.blank? + raw_repository.license(false) + end + cache_method :license_licensee - licensee_object - rescue Licensee::InvalidLicense => e - Gitlab::ErrorTracking.track_exception(e) - nil + def license_gitaly + return unless exists? + + raw_repository.license(true) end - memoize_method :license + cache_method :license_gitaly def gitignore file_on_head(:gitignore) @@ -787,8 +789,8 @@ class Repository Commit.order_by(collection: commits, order_by: order_by, sort: sort) end - def branch_names_contains(sha) - raw_repository.branch_names_contains_sha(sha) + def branch_names_contains(sha, limit: 0) + raw_repository.branch_names_contains_sha(sha, limit: limit) end def tag_names_contains(sha, limit: 0) |