in the file: core/lib/Drupal/Core/Menu/LocalTaskManager.php,

There is an unused variable found. $routes.
But it has comment like

 // Pre-fetch all routes involved in the tree. This reduces the number
    // of SQL queries that would otherwise be triggered by the access manager.
    $routes = $route_names ? $this->routeProvider->getRoutesByNames($route_names) : array();

Confirmed : the variable is unused any where else.

CommentFileSizeAuthor
#4 2609114-4.patch813 bytesrakesh.gectcr
#2 2609114-1.patch720 bytesrakesh.gectcr

Comments

rakesh.gectcr created an issue. See original summary.

rakesh.gectcr’s picture

StatusFileSize
new720 bytes

In the attached patch which i removed the variable.

chx’s picture

Status: Needs review » Needs work
    // Pre-fetch all routes involved in the tree. This reduces the number
    // of SQL queries that would otherwise be triggered by the access manager.

Normally I would recommend putting a note on RouteProviderInterface::getRoutesByNames saying it is expected to help with such optimization but since it's Symfony, you can't fix it. If you feel very adventurous you can file an upstream PR for documentation saying so but I doubt they would accept it.

So just change the code to

if ($route_names) {
  $this->routeProvider->getRoutesByNames($route_names);
}

because according to the comment this leads to a speedup and in the SQL implementation it does.

rakesh.gectcr’s picture

Status: Needs work » Needs review
StatusFileSize
new813 bytes

@chx,

You rocks!
I have done the changes according to your comment.

chx’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quickfix
dawehner’s picture

Is it just me that given that #2 passed we should ideally create some test coverage here?

tim.plunkett’s picture

Component: other » routing system
Status: Reviewed & tested by the community » Needs work
Issue tags: -rc eligible +Needs tests

Agreed.

chx’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests

Disagreed. #2 passed because it removed a performance optimization but nothing else. The comment clearly tells you this. What do you want to test? That the SQL implementation of getRoutesByNames preloades and then getRoutesByName doesn't hit the database? That doesn't belong to this issue.

dawehner’s picture

So yeah what @tim.plunkett and @dawehner wants to test:
We want to ensure that we preload the routes, which is non obvious, especially, with nested local tasks ...

dawehner’s picture

Right, this issue is also not 'rc eligible' because it touches non test code.

chx’s picture

Issue tags: +rc target triage

Well, to be honest, it removes a not used variable and does not do anything else.

  • xjm committed 2e62367 on 8.0.x
    Issue #2609114 by rakesh.gectcr, chx, dawehner, tim.plunkett: Unused...
xjm’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -rc target triage +rc target

Thanks! Normally we could call this RC eligible since it is only removing an unused variable, actually, but it makes sense to check in this case since it's changing a line of code. So tagging as an RC target.

I don't think we need tests here. The inline comment already tells us what we need to know, and the original patch in #2 was problematic because it did not heed the inline comment.

Since this particular unused variable removal involves changing an existing line of code, it makes sense to have it in its own issue. However, for the related issues that just involve deleting a line that has an unused variable -- those are very easy to review as a single scope by checking for the variable in scope and (as we discovered on this issue) reading the removed line and lines around it. So let's combine those other issues in #2610116: Removing unused variables, but committed and pushed this one to 8.0.x. Thanks!

dawehner’s picture

Wow, did we really committed this without test coverage?

  • xjm committed 2e62367 on 8.1.x
    Issue #2609114 by rakesh.gectcr, chx, dawehner, tim.plunkett: Unused...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.