Fireorm currently requires fetching a complete document, updating it, and then passing it to the update() function for any changes. This approach can lead to performance issues and potential data consistency problems when different fields of the same document are being updated concurrently. Implementing partial updates, similar to Firestore's native capabilities, would resolve these issues.
Steps to Reproduce
Create a model with multiple fields.
Attempt to update a single field of a document using Fireorm without fetching the entire document first.
Notice that the current implementation does not support partial updates.
Expected Behavior
Ability to update specific fields of a document without fetching the entire document, using a configuration to specify the update strategy.
Actual Behavior
Currently, the entire document must be fetched, updated, and then saved, leading to potential performance and data consistency issues.
Acceptance Criteria
Implement support for partial updates in Fireorm.
Add a flag at initialization (updateStrategy: 'replace' | 'merge') with replace as the default.
Allow the repository update method to accept a configuration object as a second parameter to locally override the global setting.
Additional Context
July 8, 2020: Initial issue raised about the limitation of requiring complete objects for updates.
January 21, 2021: Comment on the potential data consistency issues when updating different fields concurrently.
February 20, 2021: Proposed implementation strategy to add a flag for update strategy and allow local overrides.
Proposed API Changes
Global Update Strategy Configuration:
Introduce a global configuration option during Fireorm initialization to set the default update strategy.
initialize({ updateStrategy: 'merge' });
Local Override for Update Method:
Allow the update method to accept a second parameter for configuration, enabling local override of the update strategy.
Description
Fireorm currently requires fetching a complete document, updating it, and then passing it to the
update()
function for any changes. This approach can lead to performance issues and potential data consistency problems when different fields of the same document are being updated concurrently. Implementing partial updates, similar to Firestore's native capabilities, would resolve these issues.Steps to Reproduce
Expected Behavior
Ability to update specific fields of a document without fetching the entire document, using a configuration to specify the update strategy.
Actual Behavior
Currently, the entire document must be fetched, updated, and then saved, leading to potential performance and data consistency issues.
Acceptance Criteria
updateStrategy: 'replace' | 'merge'
) withreplace
as the default.update
method to accept a configuration object as a second parameter to locally override the global setting.Additional Context
Proposed API Changes
Global Update Strategy Configuration:
Local Override for Update Method:
update
method to accept a second parameter for configuration, enabling local override of the update strategy.Implementation Details:
update
method in the repository to handle partial updates based on the configured strategy.replace
strategy.Example Implementation
Original Issue