Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashfile/checkout: use save_many to save state #545

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/dvc_data/hashfile/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import TYPE_CHECKING, Optional

from dvc_objects.fs.generic import test_links, transfer
from dvc_objects.fs.local import LocalFileSystem
from fsspec.callbacks import DEFAULT_CALLBACK

from .build import build
Expand All @@ -13,6 +14,7 @@
from fsspec import Callback

from ._ignore import Ignore
from .hash_info import HashInfo

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -110,10 +112,6 @@ def _checkout_file(
else:
link(cache, cache_path, fs, path)
modified = True

if state:
state.save(path, fs, change.new.oid)

return modified


Expand Down Expand Up @@ -178,7 +176,7 @@ def __call__(self, cache, from_path, to_fs, to_path):
raise LinkError(to_path) from exc


def _checkout(
def _checkout( # noqa: C901
diff,
path,
fs,
Expand All @@ -203,6 +201,8 @@ def _checkout(
_remove(entry_path, fs, change.old.in_cache, force=force, prompt=prompt)

failed = []
hashes_to_update: list[tuple[str, HashInfo, None]] = []
is_local_fs = isinstance(fs, LocalFileSystem)
for change in chain(diff.added, diff.modified):
entry_path = fs.join(path, *change.new.key) if change.new.key != ROOT else path
if change.new.oid.isdir:
Expand All @@ -223,6 +223,13 @@ def _checkout(
)
except CheckoutError as exc:
failed.extend(exc.paths)
else:
if is_local_fs:
info = fs.info(entry_path)
hashes_to_update.append((entry_path, change.new.oid, info))

if state is not None:
state.save_many(hashes_to_update, fs)

if failed:
raise CheckoutError(failed)
Expand Down
Loading