state: bulk sql for unused links deletion

This commit is contained in:
pared
2019-06-28 13:52:59 +02:00
committed by pawel
parent 8c2fa8d00a
commit ff1809b060
2 changed files with 22 additions and 3 deletions
+4 -3
View File
@@ -449,6 +449,7 @@ class State(StateBase): # pylint: disable=too-many-instance-attributes
remove(path)
unused.append(relpath)
for relpath in unused:
cmd = "DELETE FROM {} WHERE path = ?".format(self.LINK_STATE_TABLE)
self._execute(cmd, (relpath,))
cmd = "DELETE FROM {} WHERE path IN ({})".format(
self.LINK_STATE_TABLE, ",".join(["?"] * len(unused))
)
self._execute(cmd, tuple(unused))
+18
View File
@@ -77,3 +77,21 @@ class TestGetStateRecordForInode(TestDvc):
state.save(PathInfo(path), md5)
ret = state.get_state_record_for_inode(inode)
self.assertIsNotNone(ret)
def test_remove_unused_links(repo_dir, dvc_repo):
stages = dvc_repo.add(repo_dir.FOO)
assert len(stages) == 1
stages = dvc_repo.add(repo_dir.BAR)
assert len(stages) == 1
cmd_count_links = "SELECT count(*) FROM {}".format(State.LINK_STATE_TABLE)
with dvc_repo.state:
result = dvc_repo.state._execute(cmd_count_links).fetchone()[0]
assert result == 2
dvc_repo.state.remove_unused_links([])
result = dvc_repo.state._execute(cmd_count_links).fetchone()[0]
assert result == 0