diff options
author | Hiroyuki Sato <h-sato@ruby-dev.jp> | 2016-12-20 22:43:59 +0900 |
---|---|---|
committer | Hiroyuki Sato <h-sato@ruby-dev.jp> | 2016-12-20 22:43:59 +0900 |
commit | 1a59766d0c7ed78a7167040af512842979d2414e (patch) | |
tree | 7687c37762986681fc2f459bed188ef61e3663ca | |
parent | e78f1048d9f9e327f6386dbeae020a2217d8e05f (diff) | |
download | gitlab-ce-1a59766d0c7ed78a7167040af512842979d2414e.tar.gz |
Merge two methods.
-rw-r--r-- | app/models/repository.rb | 11 | ||||
-rw-r--r-- | lib/api/files.rb | 2 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 10 |
3 files changed, 10 insertions, 13 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 58eab25b283..3266e9c75f0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -654,19 +654,16 @@ class Repository end def last_commit_for_path(sha, path) - sha = cache_last_commit_id_for_path(sha, path) + sha = last_commit_id_for_path(sha, path) commit(sha) end def last_commit_id_for_path(sha, path) - args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path}) - Gitlab::Popen.popen(args, path_to_repo).first.strip - end - - def cache_last_commit_id_for_path(sha, path) key = path.blank? ? "last_commit_id_for_path:#{sha}" : "last_commit_id_for_path:#{sha}:#{Digest::SHA1.hexdigest(path)}" + cache.fetch(key) do - last_commit_id_for_path(sha, path) + args = %W(#{Gitlab.config.git.bin_path} rev-list --max-count=1 #{sha} -- #{path}) + Gitlab::Popen.popen(args, path_to_repo).first.strip end end diff --git a/lib/api/files.rb b/lib/api/files.rb index f95b9be1722..779f54c1ded 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -70,7 +70,7 @@ module API ref: params[:ref], blob_id: blob.id, commit_id: commit.id, - last_commit_id: repo.cache_last_commit_id_for_path(commit.sha, params[:file_path]) + last_commit_id: repo.last_commit_id_for_path(commit.sha, params[:file_path]) } end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9c66bbdb5f3..af7e89eae05 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -142,16 +142,16 @@ describe Repository, models: true do describe '#last_commit_id_for_path' do subject { repository.last_commit_id_for_path(sample_commit.id, '.gitignore') } - it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } - end + it "returns last commit id for a given path" do + is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') + end - describe '#cache_last_commit_id_for_path' do - it "caches #last_commit_id_for_path" do + it "caches last commit id for a given path" do cache = repository.send(:cache) key = "last_commit_id_for_path:#{sample_commit.id}:#{Digest::SHA1.hexdigest('.gitignore')}" expect(cache).to receive(:fetch).with(key).and_return('c1acaa5') - expect(repository.cache_last_commit_id_for_path(sample_commit.id, '.gitignore')).to eq('c1acaa5') + is_expected.to eq('c1acaa5') end end |