WIP: Notes sync implementation #458

Draft
blacklight wants to merge 54 commits from 457/notes-sync into master
Owner
No description provided.
blacklight added this to the v1.4.0 milestone 2025-08-24 20:24:32 +02:00
Models the [local_note] <--synced_from-- [remote_note] relationship
- Refactor BaseNotePlugin to replace `_last_sync_time` with
  `_last_local_sync_time` and update related methods for consistency.

- Introduce sync fields in NoteItemSchema for tracking synced notes,
  ensuring minimal information is returned during serialization. This
  improves clarity in synchronization processes and reinforces naming
  conventions across the codebase.
This is now required because `fold_records` may contain records from
multiple plugins, since synced notes are persisted, and those may have
the same logical IDs.
Merge branch 'master' into 457/notes-sync
All checks were successful
continuous-integration/drone/push Build is passing
1076107fe0
* master:
  feat(core): Added `--debug-sql` CLI option
  [Automatic] Updated components cache
This makes responses to e.g. `get_notes` smaller and prevents loops.
This prevents recursion loops in the `_[to|from]_db_note` methods.

This commit also adds a more explicit flush/commit behaviour to db
sessions.
Update relationships in the database model to accommodate these changes
and ensure proper synchronization.
[notes] Ensure that content is always set on [create|edit]_note
All checks were successful
continuous-integration/drone/push Build is passing
0b8a268d70
Also in this commit:

- Defined the `infer_id` method for the local notes plugin (a local note
  ID is always its path).

- Call `stop_remote_sync` in the local note plugin when it stops.
[notes] Initial notes sync implementation
All checks were successful
continuous-integration/drone/push Build is passing
50e3ad8e75
- `build`
- `to_dict`
- `__eq__`
[notes] Implemented continuous sync logic
All checks were successful
continuous-integration/drone/push Build is passing
3fc8e83250
[notes] Preserve note references on sync
All checks were successful
continuous-integration/drone/push Build is passing
18f865ce7f
Otherwise, especially on SQLite, there's a high chance of leaving behind
a locked database.

This commit also fixes some minor style warnings in the db module.
This is to prevent cases where e.g. a draft note is deleted and a new
one is persisted under the same path (but with different IDs).

Other plugins rely on the full path of a note to infer their
synchronization state. Such cases result in state deltas that have both
added and deleted events for the same path, which can result in
undefined behaviour.

It is instead required to scan the state delta before processing it and
group changed notes by path, and then pick only the most recently
updated one.
[notes] Always ensure that sync_from and sync_to are lists of objects
All checks were successful
continuous-integration/drone/push Build is passing
e019721e88
[notes] Added conflicting_for property to notes
All checks were successful
continuous-integration/drone/push Build is passing
69b01fc20d
If the note is a _virtual_ note, and it's actually a copy of a remote
note that a locally synced one is in conflict with, then
`conflicting_for` will contain the local conflicting copy, while the
current note contains a copy of the remote reference.

If a note has `conflicting_for` set, it will also have
`is_conflict_note` set to True.
blacklight force-pushed 457/notes-sync from 69b01fc20d
All checks were successful
continuous-integration/drone/push Build is passing
to dbc685ce45
All checks were successful
continuous-integration/drone/push Build is passing
2025-08-29 19:52:02 +02:00
Compare
_merge_remote_note_relations -> _merge_note_relations

Since it can be called from any context where we need to merge an
incoming note without relations with a synced copy with the properly
stored relations.
A note can have 0-1 `conflicting_for` relations
- `Note.build` should initialize `conflicting_for` separately.
- `Note.__eq__` shouldn't compare attributes like `id` and `plugin`
  which will probably differ if a note is remotely synchronized.
[notes] Refactored sync mixin
All checks were successful
continuous-integration/drone/push Build is passing
4fc18d3861
- Added a new prefix for conflict note titles.
- Created methods to update existing conflict notes and create new
  conflict notes.
- Refactored `_merge_notes` to utilize the new conflict handling
  methods.
- Improved readability and maintainability by extracting merging logic
  into dedicated methods.
Merge branch 'master' into 457/notes-sync
All checks were successful
continuous-integration/drone/push Build is passing
8f5af57005
* master:
  fix(ntfy): Variable name clash in `ntfy.send_message`
fix(db): Properly handle on_duplicate_update on MariaDB
All checks were successful
continuous-integration/drone/push Build is passing
a68bf48245
MariaDB does not support the RETURNING clause, which causes `db.insert`
calls with `on_duplicate_update` to fail.

This commit adds error handling to manage this case gracefully, just
like it's done for SQLite.
Refactor notes handling in the Platypush project.
All checks were successful
continuous-integration/drone/push Build is passing
561dfe381a
- Added logger for debugging in notes.py.
- Moved infer ID property to the Note class.
- Updated digest computation to handle trimmed content in Note class.
- Excluded specific fields (`synced_from`, `synced_to`,
  `conflict_notes`, `conflicting_for`) from database note attributes.
- Improved note synchronization process in SyncMixin by adjusting field
  merges and ensuring proper conflict detection.
- Enhanced conflict resolution logging to assist with debugging.
Reviewed-on: #461
Merge branch 'master' into 457/notes-sync
Some checks failed
continuous-integration/drone/push Build is failing
d5f4c2fbaa
* master:
  fix(ui): Fixed handling of focus/blur/submit events in Autocomplete and ActionEditor
  Bump version: 1.3.6 → 1.3.7
  Updated CHANGELOG
  [Automatic] Updated components cache
  fix(db): Properly handle `on_duplicate_update` on MariaDB
  fix(db): Use sqlalchemy.Uuid instead of sqlalchemy.UUID
  [Automatic] Updated components cache
  A marshmallow schema shouldn't extend ABC
  [Automatic] Updated components cache
* master:
  fix(ui): Better handling of focus after action execution
  fix(ui): Fixed some Vue layout warnings
  [Automatic] Updated UI files
Merge branch 'master' into 457/notes-sync
All checks were successful
continuous-integration/drone/push Build is passing
5f53ecb336
* master:
  Improve payload handling in webhook route
  [Automatic] Updated UI files
blacklight removed this from the v1.4.0 milestone 2025-12-19 02:02:11 +01:00
This pull request has changes conflicting with the target branch.
  • platypush/plugins/notes/_base.py
  • platypush/plugins/notes/mixins/db.py
  • platypush/plugins/notes/mixins/index.py
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 457/notes-sync:457/notes-sync
git switch 457/notes-sync

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff 457/notes-sync
git switch 457/notes-sync
git rebase master
git switch master
git merge --ff-only 457/notes-sync
git switch 457/notes-sync
git rebase master
git switch master
git merge --no-ff 457/notes-sync
git switch master
git merge --squash 457/notes-sync
git switch master
git merge --ff-only 457/notes-sync
git switch master
git merge 457/notes-sync
git push origin master
Sign in to join this conversation.
No description provided.