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

avoid duplicate requests to the cache proxy. #126

Merged
merged 1 commit into from
Nov 14, 2014

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Sep 1, 2014

fix #125

@@ -347,6 +347,8 @@ function ($requests) use ($self) {
$varnish
->purge('/c')
->purge('/b')
->purge('/b')
->purge('/b')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good enough as test?

Copy link
Member

Choose a reason for hiding this comment

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

you should add a test using headers

@dbu dbu force-pushed the no-duplicate-proxy-requests branch from a76b98d to ec7540e Compare September 2, 2014 02:55
@dbu
Copy link
Contributor Author

dbu commented Sep 2, 2014

thanks stof. sorting the headers now, and added a separate explicit test which includes the headers.

@@ -130,7 +130,10 @@ public function flush()
*/
protected function queueRequest($method, $url, array $headers = array())
{
$this->queue[] = $this->createRequest($method, $url, $headers);
$signature = md5($method . "\n" . $url . "\n" . implode("\n", ksort($headers)));
Copy link
Member

Choose a reason for hiding this comment

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

ksort modifies the array by reference, it does not return a sorted array.

And you should probably move the generation of the signature to a private method, or use a different variable for the sorted array. We should try to keep the submitted headers in the provided order if possible

@dbu dbu force-pushed the no-duplicate-proxy-requests branch from ec7540e to a0ffbaa Compare September 2, 2014 15:38
@dbu
Copy link
Contributor Author

dbu commented Sep 2, 2014

good thing with the test, actually found a bug. alright, moved that to a method and did the sorting correctly. the header order should only matter to the user debugging what is going on. if we have 2 requests with different order, we will only see one of them being sent, so if order would technically matter there would be a problem.

*
* @return string A hash value for this request.
*/
private function getSignature($method, $url, array $headers)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this means that if somebody overwrites queueRequest, he will either have to copy this method or not use a hash. should we make it protected?

Copy link
Member

Choose a reason for hiding this comment

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

the queue is private, so you have to call the parent method anyway if you overwrite it. queueRequest is not designed to be overwritten in child classes, but to be called in child classes

@dbu dbu force-pushed the no-duplicate-proxy-requests branch from a0ffbaa to a2c253f Compare September 3, 2014 15:48
{
ksort($headers);

return md5($method . "\n" . $url . "\n" . var_export($headers, true));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now respecting the headers too.

i opt to not play around with upper/lowercase as it complicates the code (and makes it slower) for no value unless people do really weird code, in which case they just get duplicate requests but no errors.

@dbu
Copy link
Contributor Author

dbu commented Oct 21, 2014

@ddeboer ok to merge this?

@@ -42,7 +42,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a new feature but no BC break (the behaviour changes, but not sending duplicate requests sounds like it should not break anything) - so i bump the minor version.

ddeboer added a commit that referenced this pull request Nov 14, 2014
…ests

Avoid duplicate requests to the cache proxy
@ddeboer ddeboer merged commit 9ca60d9 into master Nov 14, 2014
@ddeboer ddeboer deleted the no-duplicate-proxy-requests branch November 14, 2014 14:56
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.

eliminate duplicates in cache invalidation
5 participants