status: optimization for already downloaded files

Fix #1839
This commit is contained in:
Mr. Outis
2019-04-30 17:09:04 -07:00
parent e99fc2d8e8
commit 29f58bda9b
3 changed files with 69 additions and 6 deletions
+3 -1
View File
@@ -48,8 +48,10 @@ class DataCloud(object):
@property
def _cloud(self):
"""Returns a Remote instance using the `core.remote` config"""
remote = self._core.get(Config.SECTION_CORE_REMOTE, "")
if remote != "":
if remote:
return self._init_remote(remote)
if self._core.get(Config.SECTION_CORE_CLOUD, None):
+25 -5
View File
@@ -336,7 +336,14 @@ class RemoteLOCAL(RemoteBase):
return by_md5
def status(self, checksum_infos, remote, jobs=None, show_checksums=False):
def status(
self,
checksum_infos,
remote,
jobs=None,
show_checksums=False,
download=False,
):
logger.info("Preparing to collect status from {}".format(remote.url))
title = "Collecting information"
@@ -352,12 +359,21 @@ class RemoteLOCAL(RemoteBase):
progress.update_target(title, 30, 100)
remote_exists = list(remote.cache_exists(md5s))
local_exists = self.cache_exists(md5s)
progress.update_target(title, 40, 100)
# This is a performance optimization. We can safely assume that,
# if the resources that we want to fetch are already cached,
# there's no need to check the remote storage for the existance of
# those files.
if download and sorted(local_exists) == sorted(md5s):
remote_exists = local_exists
else:
remote_exists = list(remote.cache_exists(md5s))
progress.update_target(title, 90, 100)
local_exists = self.cache_exists(md5s)
progress.finish_target(title)
self._fill_statuses(ret, local_exists, remote_exists)
@@ -436,7 +452,11 @@ class RemoteLOCAL(RemoteBase):
jobs = remote.JOBS
status_info = self.status(
checksum_infos, remote, jobs=jobs, show_checksums=show_checksums
checksum_infos,
remote,
jobs=jobs,
show_checksums=show_checksums,
download=download,
)
chunks = self._get_chunks(download, remote, status_info, status, jobs)
+41
View File
@@ -0,0 +1,41 @@
from dvc.remote.local import RemoteLOCAL
def test_status_download_optimization(mocker):
"""When comparing the status to pull a remote cache,
And the desired files to fetch are already on the local cache,
Don't check the existance of the desired files on the remote cache
"""
remote = RemoteLOCAL(None, {})
checksum_infos = [
{
"path": "foo",
"metric": False,
"cache": True,
"persist": False,
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
},
{
"path": "bar",
"metric": False,
"cache": True,
"persist": False,
"md5": "37b51d194a7513e45b56f6524f2d51f2",
},
]
local_exists = [
"acbd18db4cc2f85cedef654fccc4a4d8",
"37b51d194a7513e45b56f6524f2d51f2",
]
mocker.patch.object(remote, "cache_exists", return_value=local_exists)
other_remote = mocker.Mock()
other_remote.url = "other_remote"
other_remote.cache_exists.return_value = []
remote.status(checksum_infos, other_remote, download=True)
assert other_remote.cache_exists.call_count == 0