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 ImportExport
class CleanupService
RESERVED_REFS_NAMES =
def self.reserved_refs_names
%w[heads tags merge-requests keep-around environments]
RESERVED_REFS_REGEXP =
%r{\Arefs/(?:#{
RESERVED_REFS_NAMES.map(&Regexp.method(:escape)).join('|')})/}x
end
def self.reserved_refs_regexp
names = reserved_refs_names.map(&Regexp.method(:escape)).join('|')
%r{\Arefs/(?:#{names})/}
end
attr_reader :project
......@@ -23,8 +27,12 @@ module Projects
private
def garbage_refs
@garbage_refs ||= rugged.references.reject do |ref|
ref.name =~ RESERVED_REFS_REGEXP
@garbage_refs ||= begin
reserved_refs_regexp = self.class.reserved_refs_regexp
rugged.references.reject do |ref|
ref.name =~ reserved_refs_regexp
end
end
end
......
......@@ -37,7 +37,7 @@ describe Projects::ImportExport::CleanupService do
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
before do
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