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

[WIP] Add type on annotation and handle it #161

Closed
wants to merge 4 commits into from
Closed

[WIP] Add type on annotation and handle it #161

wants to merge 4 commits into from

Conversation

lepiaf
Copy link

@lepiaf lepiaf commented Nov 21, 2014

PR for #160

I have to replace UrlGenerator with Router because I need to know if a route has parameters, and then replace all token with a wildcard.

I also change method scope to protected. It make possible to fit for special need.

@ddeboer
Copy link
Member

ddeboer commented Nov 21, 2014

We should keep purge as the default type so we don't break BC.

@@ -220,6 +226,26 @@ private function invalidateRoutes(array $routes, Request $request)
}
}

if (null === $route->getParams()) {
$route = $this->router->getRouteCollection()->get($route->getName());
Copy link
Member

Choose a reason for hiding this comment

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

Last time I checked, getRouteCollection() gets an uncached set of routes. Clearly, this is not desirable.

Copy link
Author

Choose a reason for hiding this comment

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

ok, how can we check if there are params on route ?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

#line 209 in Symfony/src/Component/Routing/Router.php
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
{
    return $this->getGenerator()->generate($name, $parameters, $referenceType);
}
#line 137 in Symfony/src/Component/Routing/Generator/UrlGenerator.php
// the Route has a cache of its own and is not recompiled as long as it does not get modified
$compiledRoute = $route->compile();

It safe to use Router.php.

Copy link
Member

Choose a reason for hiding this comment

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

your code snippets don't do anything to prove @ddeboer is wrong (and this is logical, because he is not)

@@ -148,7 +148,7 @@ public static function getSubscribedEvents()
*
* @param Request $request
*/
private function handleInvalidation(Request $request, Response $response)
protected function handleInvalidation(Request $request, Response $response)
Copy link
Contributor

Choose a reason for hiding this comment

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

why convert all methods to protected? this will make it hard to work on the code and keep BC.

Copy link
Author

Choose a reason for hiding this comment

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

It make easier to override method, especially for specific need in ban or purge.

@dbu
Copy link
Contributor

dbu commented Nov 21, 2014

why don't we add a new annotation invalidateRegex, just as we have different commands for the cli? that way things would be more straightforward.

either way, to allow to specify a route name instead of a regex, we need to "compile" the route ourselves by using Route::getPath() and Route::getRequirements() to replace {placeholder} with the correct requirement (or .* if no requirement is defined). that would be most exact but not collide with requirements in the generator.

protected function preFillParams($route)
{
$params = array();
$route = $this->router->getRouteCollection()->get($route->getName());
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure where the previous comments went, but we need to find a solution for this. i don't know what we can do - the unfortunate thing is that we can't find annotations at cache:warmup time or we could just precompile all this and not care much about performance.

Copy link
Member

Choose a reason for hiding this comment

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

Just for reference, this is how I solved this before: driebit/DriebitHttpCacheBundle@c238a86. Unfortunately, I don’t think this solution will suffice here.

@dbu
Copy link
Contributor

dbu commented Nov 25, 2014

thanks a lot for updating. yeah i think this way it can work.

what about my question:

why don't we add a new annotation invalidateRegex, just as we have different commands for the
cli? that way things would be more straightforward.
do you have an opinion @ddeboer ? i would hope to keep the code more readable and at the same time make it more expressive for the user what he is doing.

about our performance worry: Router::getGenerator is setting up the UrlGenerator with a fresh collection and then caches it. so having the whole collection around seems normal. but i am not sure if its that costly to get the collection on the fly. for configured routes, this will all have been compiled when updating the cache after editing a routing file, no?

@ddeboer
Copy link
Member

ddeboer commented Nov 25, 2014

Performance: is symfony/symfony#7368 (comment) not actual anymore?

@dbu
Copy link
Contributor

dbu commented Nov 26, 2014

@stof in the symfony issue @ddeboer mentions you asked for a use case. is this a valid usecase? or do you have a sugestion what we should do instead?

@dbu
Copy link
Contributor

dbu commented Nov 28, 2014

@ddeboer what about a separate annotation instead?
@stof do you have a suggestion how to avoid the performance penalty of loading all routes to find the one we want to invalidate? (see discussion above and the symfony issue 7368)

@ddeboer
Copy link
Member

ddeboer commented Nov 29, 2014

@dbu Separate annotation may be clearest, yes, but you lose the possibility to combine route names with wildcard parameters. So for instance, to invalidate all get_article routes with ids 1–10.

@dbu
Copy link
Contributor

dbu commented Dec 5, 2014

@ddeboer the separate annotation should not be less expressive then one that mixes up things, no?

@lepiaf stof gave an idea how to do handle the route collection without creating a performance problem: #23 (comment) - do you want to work on that?

@dbu
Copy link
Contributor

dbu commented Jan 18, 2015

ping

protected function preFillParams($routeName)
{
$params = array();
$route = $this->router->getRouteCollection()->get($routeName->getName());
Copy link
Member

Choose a reason for hiding this comment

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

please don't do this. Using ->getRouteCollection() at runtime kills your performance, because it triggers the loading of routes each time

@lepiaf
Copy link
Author

lepiaf commented Jan 18, 2015

Hi, I don't have time to work on it now. Can you open an issue and let somone else to work on it?

@dbu
Copy link
Contributor

dbu commented Jan 18, 2015

we can just leave this open for now and see if somebody wants to work on it.

@dbu
Copy link
Contributor

dbu commented Jun 14, 2015

@ddeboer what do we do with this one? i would tend to drop it, it seems very complicated. if there is somebody needing it, an option could be to add an annotation to ban on the static prefix of a route so there would be no need to integrate that deeply with the routing.

@ddeboer
Copy link
Member

ddeboer commented Jun 14, 2015

Closing this for now. @lepiaf If you feel this is still necessary and have the time to work on it, please re-open. 😄

@ddeboer ddeboer closed this Jun 14, 2015
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