mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-23 08:16:54 +00:00
Speed up initial repository access
Use os.listdir() instead of os.walk() to avoid unnecessary stat() calls. Closes #119
This commit is contained in:
parent
7b9d129bcd
commit
547fa0a590
1 changed files with 8 additions and 6 deletions
|
@ -408,12 +408,14 @@ def close(self):
|
|||
self.fds = None # Just to make sure we're disabled
|
||||
|
||||
def segment_iterator(self, reverse=False):
|
||||
for dirpath, dirs, filenames in os.walk(os.path.join(self.path, 'data')):
|
||||
dirs.sort(key=int, reverse=reverse)
|
||||
filenames = sorted((filename for filename in filenames if filename.isdigit()), key=int, reverse=reverse)
|
||||
for filename in filenames:
|
||||
yield int(filename), os.path.join(dirpath, filename)
|
||||
|
||||
data_path = os.path.join(self.path, 'data')
|
||||
dirs = sorted((dir for dir in os.listdir(data_path) if dir.isdigit()), key=int, reverse=reverse)
|
||||
for dir in dirs:
|
||||
filenames = os.listdir(os.path.join(data_path, dir))
|
||||
sorted_filenames = sorted((filename for filename in filenames
|
||||
if filename.isdigit()), key=int, reverse=reverse)
|
||||
for filename in sorted_filenames:
|
||||
yield int(filename), os.path.join(data_path, dir, filename)
|
||||
|
||||
def get_latest_segment(self):
|
||||
for segment, filename in self.segment_iterator(reverse=True):
|
||||
|
|
Loading…
Reference in a new issue