mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-20 21:27:32 +00:00
cache sync: fix n^2 behaviour in lookup_name
This commit is contained in:
parent
9f8b967a6f
commit
167875b753
1 changed files with 11 additions and 4 deletions
|
@ -588,10 +588,16 @@ def fetch_and_build_idx(archive_id, repository, key, chunk_idx):
|
|||
else:
|
||||
os.rename(fn_tmp, fn)
|
||||
|
||||
def lookup_name(archive_id):
|
||||
def get_archive_ids_to_names(archive_ids):
|
||||
# Pass once over all archives and build a mapping from ids to names.
|
||||
# The easier approach, doing a similar loop for each archive, has
|
||||
# square complexity and does about a dozen million functions calls
|
||||
# with 1100 archives (which takes 30s CPU seconds _alone_).
|
||||
archive_names = {}
|
||||
for info in self.manifest.archives.list():
|
||||
if info.id == archive_id:
|
||||
return info.name
|
||||
if info.id in archive_ids:
|
||||
archive_names[info.id] = info.name
|
||||
return archive_names
|
||||
|
||||
def create_master_idx(chunk_idx):
|
||||
logger.info('Synchronizing chunks cache...')
|
||||
|
@ -612,8 +618,9 @@ def create_master_idx(chunk_idx):
|
|||
pi = ProgressIndicatorPercent(total=len(archive_ids), step=0.1,
|
||||
msg='%3.0f%% Syncing chunks cache. Processing archive %s',
|
||||
msgid='cache.sync')
|
||||
archive_ids_to_names = get_archive_ids_to_names(archive_ids)
|
||||
for archive_id in archive_ids:
|
||||
archive_name = lookup_name(archive_id)
|
||||
archive_name = archive_ids_to_names.pop(archive_id)
|
||||
if self.progress:
|
||||
pi.show(info=[remove_surrogates(archive_name)])
|
||||
if self.do_cache:
|
||||
|
|
Loading…
Reference in a new issue