Commit bea29327 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Just use methods over constants, so that we could

take the advantage that if they're not used, we
could garbage collect those data, reducing memory
footprint.
parent 140ac8d2
module Projects module Projects
module ImportExport module ImportExport
class CleanupService class CleanupService
RESERVED_REFS_NAMES = def self.reserved_refs_names
%w[heads tags merge-requests keep-around environments] %w[heads tags merge-requests keep-around environments]
RESERVED_REFS_REGEXP = end
%r{\Arefs/(?:#{
RESERVED_REFS_NAMES.map(&Regexp.method(:escape)).join('|')})/}x def self.reserved_refs_regexp
names = reserved_refs_names.map(&Regexp.method(:escape)).join('|')
%r{\Arefs/(?:#{names})/}
end
attr_reader :project attr_reader :project
...@@ -23,8 +27,12 @@ module Projects ...@@ -23,8 +27,12 @@ module Projects
private private
def garbage_refs def garbage_refs
@garbage_refs ||= rugged.references.reject do |ref| @garbage_refs ||= begin
ref.name =~ RESERVED_REFS_REGEXP reserved_refs_regexp = self.class.reserved_refs_regexp
rugged.references.reject do |ref|
ref.name =~ reserved_refs_regexp
end
end end
end end
......
...@@ -37,7 +37,7 @@ describe Projects::ImportExport::CleanupService do ...@@ -37,7 +37,7 @@ describe Projects::ImportExport::CleanupService do
end end
end end
described_class::RESERVED_REFS_NAMES.each do |name| described_class.reserved_refs_names.each do |name|
context "with a ref in refs/#{name}/tmp" do context "with a ref in refs/#{name}/tmp" do
before do before do
repository.write_ref("refs/#{name}/tmp", sha) repository.write_ref("refs/#{name}/tmp", sha)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment