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 PersistedModel.subscribe() #1445

Merged
merged 1 commit into from
Jul 9, 2015
Merged

Add PersistedModel.subscribe() #1445

merged 1 commit into from
Jul 9, 2015

Conversation

ritch
Copy link
Member

@ritch ritch commented Jun 11, 2015

Connect to #1444

}

var where = ctx.where;
var data = ctx.instance || ctx.data;
Copy link
Member

Choose a reason for hiding this comment

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

ctx.instance.toJSON() || ctx.data?

@bajtos
Copy link
Member

bajtos commented Jun 29, 2015

As mentioned in the slack chat, I can't review this thoroughly right now. I did a quick review and didn't find any major issues, I think it's ok to merge this as it is and refine the implementation later as needed.

@BerkeleyTrue
Copy link
Contributor

This method is being renamed, correct?

});

Model.observe('before save', createChangeHandler('save', true));
Model.observe('before delete', createChangeHandler('delete', true));
Copy link
Member

Choose a reason for hiding this comment

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

In my opinion it does not make much sense to send optimistic changes from "before" hooks.

  • When running on the server, the latency of database calls is usually negligible, thus an "optimistic" update does provide much value IMO.
  • It would make sense to emit optimistic changes when running in the browser, but IIRC, the isomorphic client does not invoke operation hooks because the remote connector completely bypasses DAO methods.

I think we need to find a different solution for emitting optimistic updates.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bajtos

When running on the server, the latency of database calls is usually negligible, thus an "optimistic" update does provide much value IMO.

The purpose of an optimistic update is to avoid latency entirely. We don't have to wait for the operation to be acknowledged by the database (or rest api, other datasource) since we are only telling the client about a likely change.

I think we are disagreeing on what latency is acceptable. IMO any IO is going to add significant latency. Ideally we would emit the optimistic change right after it is sanitized. Ideally it would be emitted before timely ACL checks, but this introduces obvious vulnerabilities.

In order to move this forward, I am OK with removing this code, as it can be added later as an optimization.

@bajtos bajtos assigned ritch and unassigned bajtos Jun 30, 2015

changes.destroy = function() {
changes.removeAllListeners('error');
changes.removeAllListeners('end');
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to remove hook observers too.

I think that otherwise the list of registered hook observers will grow without limits, each DAO operation will have to invoke a lot of inactive hooks and the server will gradually slow down.

@ritch
Copy link
Member Author

ritch commented Jul 8, 2015

This method is being renamed, correct?

@BerkeleyTrue Yep... renamed to createChangeStream()

@ritch
Copy link
Member Author

ritch commented Jul 8, 2015

@bajtos I'm seeing some errors in the phantomjs tests that appear to be unrelated to this change. I'm getting them on master as well. I'd like to fix those test in another PR. Any objections?

@ritch ritch assigned bajtos and unassigned ritch Jul 8, 2015
@@ -81,7 +81,7 @@
"karma-script-launcher": "^0.1.0",
"loopback-boot": "^2.7.0",
"loopback-datasource-juggler": "^2.19.1",
"loopback-testing": "^1.1.0",
"loopback-testing": "~1.1.0",
Copy link
Member

Choose a reason for hiding this comment

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

Is there any particular reason for locking down loopback-testing version to 1.1.x?

@bajtos
Copy link
Member

bajtos commented Jul 9, 2015

I'm seeing some errors in the phantomjs tests that appear to be unrelated to this change. I'm getting them on master as well. I'd like to fix those test in another PR.

Sure, that's fine with me.

@bajtos bajtos assigned ritch and unassigned bajtos Jul 9, 2015
@bajtos
Copy link
Member

bajtos commented Jul 9, 2015

Some of my older comments were not addressed, I re-posted them on the updated diff. None of them is a blocker though, feel free to land this PR without addressing them.

For the sake of our future selves, it would be good to explain why do you need to lock the version of loopback-testing to 1.1.x (see #1445 (comment)).

@ritch
Copy link
Member Author

ritch commented Jul 9, 2015

For the sake of our future selves, it would be good to explain why do you need to lock the version of loopback-testing to 1.1.x (see #1445 (comment)).

1.2 introduces a bug. strongloop-archive/loopback-testing#62

@ritch
Copy link
Member Author

ritch commented Jul 9, 2015

test please

ritch added a commit that referenced this pull request Jul 9, 2015
@ritch ritch merged commit cdddb08 into master Jul 9, 2015
@ritch ritch removed the #review label Jul 9, 2015
@bajtos bajtos deleted the feature/subscribe branch August 6, 2015 08:35
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.

5 participants