Commit 71e45f5a authored by Bram Schoenmakers's avatar Bram Schoenmakers

Don't write to the filesystem when trimming.

ChangeSet._trim may call ChangeSet.delete() several times, which incurs
a disk write every time. This creates a lot of overhead, especially when
lots of revisions are removed.

Instead, leave the responsibility to the caller of _trim to make sure
that the new content is written to disk. In this case, ChangeSet.save()
the only caller, already writes to disk.
parent 4d7150a0
...@@ -110,7 +110,7 @@ class ChangeSet(object): ...@@ -110,7 +110,7 @@ class ChangeSet(object):
self._write() self._write()
self.close() self.close()
def delete(self, p_timestamp=None): def delete(self, p_timestamp=None, p_write=True):
""" Removes backup from the backup file. """ """ Removes backup from the backup file. """
timestamp = p_timestamp or self.timestamp timestamp = p_timestamp or self.timestamp
index = self._get_index() index = self._get_index()
...@@ -119,7 +119,9 @@ class ChangeSet(object): ...@@ -119,7 +119,9 @@ class ChangeSet(object):
del self.backup_dict[timestamp] del self.backup_dict[timestamp]
index.remove(index[[change[0] for change in index].index(timestamp)]) index.remove(index[[change[0] for change in index].index(timestamp)])
self._save_index(index) self._save_index(index)
self._write()
if p_write:
self._write()
except KeyError: except KeyError:
pass pass
...@@ -143,12 +145,15 @@ class ChangeSet(object): ...@@ -143,12 +145,15 @@ class ChangeSet(object):
""" """
Removes oldest backups that exceed the limit configured in backup_count Removes oldest backups that exceed the limit configured in backup_count
option. option.
Does not write back to file system, make sure to call self._write()
afterwards.
""" """
index = self._get_index() index = self._get_index()
backup_limit = config().backup_count() - 1 backup_limit = config().backup_count() - 1
for changeset in index[backup_limit:]: for changeset in index[backup_limit:]:
self.delete(changeset[0]) self.delete(changeset[0], p_write=False)
def get_backup(self, p_todolist): def get_backup(self, p_todolist):
""" """
......
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