diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-26 17:29:33 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-26 17:36:26 +0000 |
commit | 8cd229f90dfd399debca0f86e4a740f298c6fbf7 (patch) | |
tree | 743f8d12617152a12eb5766cac802d01b521652a | |
parent | 7fbfb1998a0757b843d63cba0b43294a53891f95 (diff) | |
download | gitlab-ce-store-only-non-head-keep-arounds.tar.gz |
Reduce amount of stored keep aroundsstore-only-non-head-keep-arounds
We try to normalize keep around to tip of default branch
to not store duplicate refs unless strictly needed.
-rw-r--r-- | app/models/repository.rb | 35 | ||||
-rw-r--r-- | changelogs/unreleased/store-only-non-head-keep-arounds.yml | 5 |
2 files changed, 30 insertions, 10 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index ff355295862..eb562497695 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -264,16 +264,10 @@ class Repository # For Geo's sake, pass in multiple shas rather than calling it multiple times, # to avoid unnecessary syncing. def keep_around(*shas) - shas.each do |sha| - next unless sha.present? && commit_by(oid: sha) - - next if kept_around?(sha) - - # This will still fail if the file is corrupted (e.g. 0 bytes) - raw_repository.write_ref(keep_around_ref_name(sha), sha) - rescue Gitlab::Git::CommandError => ex - Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}" - end + shas + .map(&method(:transform_keep_around)) + .uniq + .each(&method(:store_keep_around)) end def kept_around?(sha) @@ -1066,6 +1060,27 @@ class Repository private + def transform_keep_around(sha) + # transform sha to head sha + # to reduce amount of created + # keep arounds + if head_sha = head_commit&.sha + return head_sha if raw_repository.ancestor?(sha, head_sha) + end + + sha + end + + def store_keep_around(sha) + return unless sha.present? && commit_by(oid: sha) + return if kept_around?(sha) + + # This will still fail if the file is corrupted (e.g. 0 bytes) + raw_repository.write_ref(keep_around_ref_name(sha), sha) + rescue Gitlab::Git::CommandError => ex + Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}" + end + # TODO Generice finder, later split this on finders by Ref or Oid # gitlab-org/gitlab-ce#39239 def find_commit(oid_or_ref) diff --git a/changelogs/unreleased/store-only-non-head-keep-arounds.yml b/changelogs/unreleased/store-only-non-head-keep-arounds.yml new file mode 100644 index 00000000000..5872d43009c --- /dev/null +++ b/changelogs/unreleased/store-only-non-head-keep-arounds.yml @@ -0,0 +1,5 @@ +--- +title: Reduce amount of keep arounds +merge_request: +author: +type: performance |