Skip to content

Commit

Permalink
Only clear dirty bit after nodes are persisted
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiz committed Apr 13, 2024
1 parent d56a9e3 commit 4ac0438
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 70 deletions.
29 changes: 20 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,15 +1087,22 @@ 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,
)

# Clear
for node in updated_nodes:
node.clean()
for label in updated_labels:
label.clean()

if changes.get("forceFullResync"):
raise exception.ResyncRequiredException("Full resync required")

Expand Down
Loading

0 comments on commit 4ac0438

Please sign in to comment.