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

PageBookamrks – New Synced DB #683

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

mohannad-hassan
Copy link
Collaborator

First draft: shows a working example for a GRDB stack for page bookmarks. Tests will be similar to the CoreData variant, except that the GRDB's integration with Combine doesn't guarantee that publishers will signal every time the resources is mutated, instead it might aggregate a few mutations together.

Also, still remains to test the publisher function in DatabaseConnection.

Copy link

codecov bot commented Feb 9, 2025

Codecov Report

Attention: Patch coverage is 91.55844% with 13 lines in your changes missing coverage. Please review.

Project coverage is 41.11%. Comparing base (d9fc366) to head (7b5b640).
Report is 42 commits behind head on main.

Files with missing lines Patch % Lines
...ce/Sources/GRDBSyncedPageBookmarkPersistence.swift 75.00% 12 Missing ⚠️
...Tests/GRDBSyncedPageBookmarkPersistenceTests.swift 97.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #683      +/-   ##
==========================================
+ Coverage   40.92%   41.11%   +0.18%     
==========================================
  Files         525      541      +16     
  Lines       20880    21838     +958     
==========================================
+ Hits         8546     8978     +432     
- Misses      12334    12860     +526     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mohannad-hassan mohannad-hassan marked this pull request as ready for review February 9, 2025 16:25
@mohannad-hassan mohannad-hassan changed the title [WIP] GRDB Migration PageBookamrks – New Synced DB Feb 10, 2025
Copy link
Collaborator

@mohamede1945 mohamede1945 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work, Mohannad! I like the test cases a lot too. Just a couple of small changes and we should be good to go inshaa'Allah.

Comment on lines 12 to 14
func syncedPageBookmarksPublisher() throws -> AnyPublisher<[SyncedPageBookmarkPersistenceModel], Never>
func insert(bookmark: SyncedPageBookmarkPersistenceModel) async throws
func removeBookmark(withRemoteID remoteID: String) async throws
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Sync'd bookmarks, I believe page should be the key not the remoteID. Hence, I suggest the removeBookmark to take the page instead of remote Id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since synched bookmarks reflect the state in the server, I guess it's safer to assume the logic of the backend. The usecase for removing a bookmark from this repository is when we receive a delete event in synchronizing with the server.

There's also another possibility where the app deletes a bookmark locally, but then this will go through the same channel when synchronizing with the server, and we'd retain the remote ID in the local DB as well, but not as a primary key.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick to bookmark.page being the primary key to make it explicit that we would never have 2 bookmark entries with the same page.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we add a unique constraint on page and keep the primary key for remote_id?

This way we can keep the two ideas; signaling that page is unique and that the design of the synced database follows the server's design.

BTW, this will be different in both the local database and the app's model.

Package.swift Outdated Show resolved Hide resolved
Package.swift Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants