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

Only clear dirty bit after nodes are persisted #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 14 additions & 9 deletions src/gkeepapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,9 @@ def login(
Raises:
LoginException: If there was a problem logging in.
"""
logger.warning("'Keep.login' is deprecated. Please use 'Keep.authenticate' instead")
logger.warning(
"'Keep.login' is deprecated. Please use 'Keep.authenticate' instead"
)
auth = APIAuth(self.OAUTH_SCOPES)
if device_id is None:
device_id = f"{get_mac():x}"
Expand All @@ -716,7 +718,9 @@ def resume(
sync: bool = True,
device_id: str | None = None,
) -> None:
logger.warning("'Keep.resume' has been renamed to 'Keep.authenticate'. Please update your code")
logger.warning(
"'Keep.resume' has been renamed to 'Keep.authenticate'. Please update your code"
)
self.authenticate(email, master_token, state, sync, device_id)

def authenticate(
Expand Down Expand Up @@ -787,8 +791,8 @@ def dump(self) -> dict:
nodes.extend(node.children)
return {
"keep_version": self._keep_version,
"labels": [label.save(False) for label in self.labels()],
"nodes": [node.save(False) for node in nodes],
"labels": [label.save(False, True) for label in self.labels()],
"nodes": [node.save(False, True) for node in nodes],
}

def restore(self, state: dict) -> None:
Expand Down Expand Up @@ -1018,7 +1022,7 @@ def labels(self) -> list[_node.Label]:
"""
return list(self._labels.values())

def __UNSTABLE_API_uploadMedia(self, fh: IO)-> None:
def __UNSTABLE_API_uploadMedia(self, fh: IO) -> None:
pass

def getMediaLink(self, blob: _node.Blob) -> str:
Expand Down Expand Up @@ -1083,12 +1087,13 @@ def _sync_notes(self) -> None:
logger.debug("Starting keep sync: %s", self._keep_version)

# Collect any changes and send them up to the server.
labels_updated = any(i.dirty for i in self._labels.values())
updated_nodes = self._findDirtyNodes()
updated_labels = [label for label in self._labels.values() if label.dirty]
changes = self._keep_api.changes(
target_version=self._keep_version,
nodes=[i.save() for i in self._findDirtyNodes()],
labels=[i.save() for i in self._labels.values()]
if labels_updated
nodes=[i.save(False) for i in updated_nodes],
labels=[i.save(False) for i in self._labels.values()]
if updated_labels
else None,
)

Expand Down
Loading
Loading