Replace bulk import with client-provided UUID document creation.#56
Merged
Conversation
Previously, the database schema included a source_local_id field on the Document entity to support idempotent bulk imports of local documents, backed by a Flyway schema migration. Remove the source_local_id column, its index, and the associated Spring Data repository queries. Delete the Flyway schema migration V3 since the backend no longer tracks local IDs.
…k import. Previously, Document entity IDs were always auto-generated using Hibernate's UUID strategy, and local documents had to be imported via a dedicated bulk-import API endpoint that mapped local IDs. Now, accept an optional client-provided UUID id in DocumentCreateRequest. If a document with that ID already exists for the user, return 200 OK with a message indicating it already exists. Remove the bulk import endpoints, DTOs, and corresponding controller/service tests.
Previously, clearLocalUserData cleared the entire IndexedDB database during logout or unauthenticated session clear, including guest/local documents. Add a getUserId getter to indexedDBService to check if there is an authenticated user. In clearLocalUserData, check if the current user ID is null (i.e. guest session) and avoid clearing the database to ensure guest/local documents persist across refreshes.
Previously, when offline loading failed or migration completed, the useDocument hook did not automatically retry loading the document. Add event listeners for cloud-documents-changed and local-documents-changed within useDocument to clear the backoff and trigger a reload when these migration/promotion events are fired.
…ent creation. Previously, guest documents were promoted to the user's account using bulkImportLocalDocuments, which relied on the deleted backend bulk-import API. Replace bulkImportLocalDocuments with promoteGuestDocumentsToAccount. For each guest document, call createCloudDocument with the document's existing local UUID as the requested ID, then cache it.
Previously, migrating a local document to the cloud resulted in a new cloud-generated document ID, requiring subsequent deletion of the original local document and database redirection. Now, migrateLocalDocumentToCloud and resolveRootDocumentId pass the existing local document UUID to createCloudDocument, ensuring the document ID remains identical in both local and cloud databases.
Previously, creating a new document offline or online did not use a consistent pre-generated ID schema, relying on separate random UUIDs for guest documents versus cloud documents. Update handleCreateFile to always generate a document ID locally using generateDocumentId, then save it local-first and, if authenticated, propagate the same ID to createCloudDocument.
…promotion. Previously, the AppShell component tracked local document sync using the naming convention of "bulk import" in state variables and refs. Refactor all references of "bulk import" to "promotion" in AppShell to reflect the new client-driven promotion strategy. Update the corresponding unit tests to verify guest document promotion.
There was a problem hiding this comment.
Code Review
This pull request refactors the document creation and migration logic to utilize client-generated UUIDs, replacing the bulk import functionality with a document promotion mechanism. Key changes include updating the backend Document entity and DocumentCreateRequest to support manual ID assignment, removing the bulk import API, and refactoring the frontend to generate IDs locally. Feedback suggests improving the implementation by moving yjsState validation to the DTO level using standard annotations and parallelizing the document promotion process in the frontend service to reduce latency.
bee46c8 to
beaf995
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactors the document creation and migration logic to utilize client-generated UUIDs, replacing the bulk import functionality with a document promotion mechanism.
This also fixes a bug where the db is cleared on refresh if the current user is in guest session.
This simplifies a lot of things in the backend. To make it completely offline-first, we could also allow users to create new documents in offline mode and edit them offline.