getDestination() gets called often for nothing

Created on 1 February 2023, over 1 year ago

Problem/Motivation

While trying to alter the paths/filenames of the exports I noticed the many calls to \Drupal\tome_static\StaticGenerator::getDestination which aren't used or seem to be needed.

1. in requestPath() right before

if ($response->isRedirection() || $response->isOk()) {

The $destination is only used inside the if. No need to have it outside.

2. in exportPaths before the copyPath() call.
I would suggest checking if the sanitized path exists before calling the getDestination-method, since it's only of use if it exists and we want to copy.
Yeah, I know, copyPath also does a file_exists(), but that doesn't bother me as much as the getDestination-calls.

Why care about those calls, they're nothing right?
1. When debuging the path-altering-stuff, it's pretty annoying to go through bunch of paths which aren't in the export anyway (for reasons, mostly 404. Probably language issues on my end. Who knows).

2. And also I'm bit worried about performance. Might not be a big deal for a small number of pages, but I'll have a multi-site thing where some sites have hundreds of pages (and each page I have to export multiple times, for reasons™ we're better not get into).

Proposed resolution

1. Just move the getDestination call inside the if
2. Do a file_exists on the sanitized path first, if that passes call getDestination to do the copyPath.

Remaining tasks

I'll provide a patch pretty soon.

User interface changes

none.

API changes

not that I can see.

Data model changes

nope.

As far as I can see this shouldn't change anything on the resulting export. As I said, the $destinations are only used inside the if-cases.

📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇩🇪Germany SerkanB

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @SerkanB
  • @serkanb opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇩🇪Germany SerkanB

    Fix for #1 works fine.

    #2 I wasn't that easy, simply doing it as I described skips all the assets. That's because in the copyPath()-method the path is being altered before file_exists() is called. I left it as is (for now)

Production build 0.71.5 2024