Skip to content

Improved performance of QueryDefaultsPlugin #94

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

Merged
merged 2 commits into from
Apr 5, 2018

Conversation

vudaltsov
Copy link
Contributor

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets #67
Documentation
License MIT

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

indeed, that looks like it should be faster.

just to be sure: could this have any kind of side effect? i guess parameter order is preserved (it should not matter, but who knows)? and the behaviour when a parameter name is repeated would also stay the same?

@vudaltsov
Copy link
Contributor Author

@dbu , yes.

$requestQuery += $defaultQuery will only add elements from default query not existing in request query (including the ones with numeric indexes) according to http://php.net/manual/en/language.operators.array.php, which is exactly the same as iterating over default query and adding to request query with !isset check.

The order will be preserved. The new array will contain elements from $requestQuery in their current order with added nonexisting elements from $defaultQuery in their original order. Same as it was before.

@vudaltsov
Copy link
Contributor Author

Could this be merged? Or can I help somehow? Maybe add more tests?

@Nyholm
Copy link
Member

Nyholm commented Feb 2, 2018

Im not sure about this. A side effect (that I think I see):

$defaults = ['foo'=>'bar'];
$query = ['foo' => 'newValue'];

// Running the plugin

$output = 'foo=bar&foo=newValue';

Right?

@vudaltsov
Copy link
Contributor Author

vudaltsov commented Feb 2, 2018

No, the output will be $output = 'foo=newValue'. We parse the given query and merge default values into it (with existing values ignored). And then encode the clean query array and pass it to request.

My solution should have no side effects.

@Nyholm
Copy link
Member

Nyholm commented Feb 9, 2018

okey. Maybe I misread the code. Is there a test that cover this case?

@vudaltsov
Copy link
Contributor Author

Sure! I hope I have time this weekend to commit such a test.

@vudaltsov
Copy link
Contributor Author

done

@vudaltsov
Copy link
Contributor Author

@Nyholm , let's merge it?

@joelwurtz
Copy link
Member

Thanks for this @vudaltsov and sorry for the wait, yes let's merge this

@joelwurtz joelwurtz merged commit 7533c2d into php-http:master Apr 5, 2018
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.

4 participants