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

[BUGFIX #4497] query/queryRecord/filter now support adapter options #4856

Merged
merged 3 commits into from Mar 29, 2018

Conversation

stefanpenner
Copy link
Member

@stefanpenner stefanpenner commented Mar 13, 2017

[fixes #4497]

@stefanpenner stefanpenner requested review from igorT and bmac March 13, 2017 19:00
@runspired
Copy link
Contributor

Thanks! Reviewing now.

let options = {};

options.adapterOptions = query.adapterOptions;
delete query.adapterOptions;
Copy link
Member

Choose a reason for hiding this comment

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

should we test that this is removed from query?

Copy link
Member

Choose a reason for hiding this comment

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

or is this already handled by an existing test?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

Copy link
Member

Choose a reason for hiding this comment

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

🤘

let options = {};

options.adapterOptions = query.adapterOptions;
delete query.adapterOptions;
Copy link
Member

Choose a reason for hiding this comment

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

should we test that this is removed from query?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed

Copy link
Member

Choose a reason for hiding this comment

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

🤘

@stefanpenner
Copy link
Member Author

we may want to consider moving adapterOptions to a third arg, not to be conflated with query

@runspired
Copy link
Contributor

we may want to consider moving adapterOptions to a third arg, not to be conflated with query

👍

@runspired
Copy link
Contributor

@hjdivad and I discussed this OOB and decided that moving to a new optional last param for adapterOptions would be best. We gated use of that param for now by enforcing the { adapterOptions } structure, which we can loosen or expand later as needed.

This has weirdness for store.filter where it becomes the 4th param, but the alternatives were equally messy and that API has been soft-deprecated for a very long time.

@runspired
Copy link
Contributor

Test failures on ember-canary are unrelated, it appears we have some breaking change to dig into unless there's a bug in Ember.

@runspired runspired merged commit b23bd2c into master Mar 29, 2018
@runspired runspired deleted the query-adapter-options branch March 29, 2018 22:09
@stefanpenner
Copy link
Member Author

👯‍♂️

@@ -143,14 +143,14 @@ export function _query(adapter, store, modelName, query, recordArray) {

if (createRecordArray) {
recordArray = recordArray || store.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query);
promise = Promise.resolve().then(() => adapter.query(store, modelClass, query, recordArray));
promise = Promise.resolve().then(() => adapter.query(store, modelClass, query, recordArray, options));
} else {
promise = Promise.resolve().then(() => adapter.query(store, modelClass, query));
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it intentional that options isn't passed along if createRecordArray is false? There isn't such a distinction in the documentation about when an included adapterOptions hash will be passed to adapter.query.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it was a mistake actually.

@runspired / @hjdivad / @igorT can you sanity check that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Speaking with @runspired he reminded me what this was intentionally, as without a record array, we cannot pass options as a fourth argument without breaking user-land arity checks. Also, creating the record array eagerly and providing it here, had some performance implications.

The plan at the time, was to eventually change this API to use an object, instead of positional arguments, to avoid this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Additional note: if the arity check says that adapter.query uses less than 4 arguments (recordArray is 4th, options is 5th), we don't pass either along.

I'm not sure we were as worried about breaking user-land arity checks as we were about the performance costs of materializing the snapshotRecordArray when we didn't need to.

If your query implementation has an arity of 4/5 and is still not receiving options, then let's dive into that; however, simply adding it into the function signature in prep for usage should be enough to receive any options that were passed in.

Copy link
Contributor

Choose a reason for hiding this comment

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

@runspired and I dug into this more, and there's an issue with the arity check where it doesn't properly detect the argument length for adapter.query. This is captured in #6232.

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.

adapterOptions not usable for query and queryRecord
5 participants