diff options
author | Mark Chao <mchao@gitlab.com> | 2018-10-04 17:16:51 +0800 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2018-10-30 15:44:55 +0800 |
commit | a4ba973e24ef6767d635c0291c9b6ce8085aef28 (patch) | |
tree | 28efdf13b834db6267fd8bd64d798d8e694b0109 /lib | |
parent | bc14e4ed1024efa1e0a411bd59e1339fb1af20c0 (diff) | |
download | gitlab-ce-a4ba973e24ef6767d635c0291c9b6ce8085aef28.tar.gz |
Allow FoundBlob to access language from gitattributes
Extract language_from_git_attributes as a concern so it can
ben included in two blob classes.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/project_search_results.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/search_results.rb | 11 |
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/gitlab/project_search_results.rb b/lib/gitlab/project_search_results.rb index 3a202d915e3..04df881bf03 100644 --- a/lib/gitlab/project_search_results.rb +++ b/lib/gitlab/project_search_results.rb @@ -82,7 +82,7 @@ module Gitlab ref: ref, startline: startline, data: data.join, - project_id: project ? project.id : nil + project: project ) end diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 6c86ad11385..b46c18c4364 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -5,8 +5,9 @@ module Gitlab class FoundBlob include EncodingHelper include Presentable + include BlobLanguageFromGitAttributes - attr_reader :id, :filename, :basename, :ref, :startline, :data, :project_id + attr_reader :id, :filename, :basename, :ref, :startline, :data, :project def initialize(opts = {}) @id = opts.fetch(:id, nil) @@ -16,17 +17,15 @@ module Gitlab @startline = opts.fetch(:startline, nil) @data = encode_utf8(opts.fetch(:data, nil)) @per_page = opts.fetch(:per_page, 20) - @project_id = opts.fetch(:project_id, nil) + @project = opts.fetch(:project, nil) end def path filename end - # Since search results often contain many items, - # not triggering lookup can avoid n+1 queries. - def language_from_gitattributes - nil + def project_id + @project&.id end def present |