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

Add a bulkUpdate function #1399

Closed
wants to merge 1 commit into from
Closed

Add a bulkUpdate function #1399

wants to merge 1 commit into from

Conversation

ssh24
Copy link
Contributor

@ssh24 ssh24 commented Jun 6, 2017

Description

Add a static method for bulkUpdate. Connectors now can call bulkUpdate to perform a bulk update on data.

connect to loopbackio/loopback-connector-cloudant#35

@ssh24 ssh24 added the apex label Jun 6, 2017
@ssh24 ssh24 self-assigned this Jun 6, 2017
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

@ssh24 TBH, I am not sure if we need an atomic version of bulkUpdate, considering that the current implementation inside loopback goes a long way to ensure consistency of data and prevent unintentional overwriting. Perhaps all we need is to modify DAO.update() API to support the needs of applyUpdate() when run against CouchDB?

Having said that, if we can find a good way how to implement atomic bulkUpdate in connectors while preserving the important features of the current implementation, then I will happily applause.

The first major issue I see in this proposal is how to correctly invoke different operation hooks that are triggered by create/update/delete operations, preserving the context options that are expected by existing hook implementations. The current design of operation hooks is a result of long design and refinement process, we need to carefully asses impact of changes.

As I commented in strongloop/loopback#3433 (comment), I would like to see a robust test suite covering bulkUpdate in juggler's shared test suite run by all connectors. This test suite should not only verify that bulkUpdate performs the right data changes (including when a conflict occurs), but also verify that operation hooks are invoked with correct context values.


var context = {
Model: Model,
options: options,
Copy link
Member

Choose a reason for hiding this comment

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

This context is not honouring the fields provided by other DAO methods for access hook. See https://loopback.io/doc/en/lb3/Operation-hooks.html#access

datas: datas,
options: options,
};
Model.notifyObserversOf('before save', context,
Copy link
Member

Choose a reason for hiding this comment

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

This context is not honouring the fields provided by other DAO methods for access hook, see https://loopback.io/doc/en/lb3/Operation-hooks.html#before-save

Also "before save" is not a correct hook name considering that bulkUpdate performs delete operations too.

var context = {
Model: Model,
datas: datas,
options: options,
Copy link
Member

Choose a reason for hiding this comment

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

See https://loopback.io/doc/en/lb3/Operation-hooks.html#persist

Again, we shouldn't be invoking "persist" for instances that are going to be deleted.

options: options,
info: info,
};
Model.notifyObserversOf('after save', context, function(err, ctx) {
Copy link
Member

Choose a reason for hiding this comment

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

See https://loopback.io/doc/en/lb3/Operation-hooks.html#after-save

Also "after save" shouldn't be invoked for records that are going to be deleted.

@ssh24
Copy link
Contributor Author

ssh24 commented Jun 6, 2017

Closing this PR. Found another way to call just the cloudant implementation of the bulkUpdate function by db.connector.bulkUpdate.

@ssh24 ssh24 closed this Jun 6, 2017
@rmg rmg deleted the feature/add-bulkUpdate branch March 18, 2021 23:46
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