-
-
Notifications
You must be signed in to change notification settings - Fork 221
BlueScreen: collapse paths usable with files #115
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
Conversation
|
This will result in multiple disk IO operations for every NDB query when ConnectionPanel is used https://github.com/nette/database/blob/187df045a31a22b2d1871e300f819ebada208799/src/Bridges/DatabaseTracy/ConnectionPanel.php#L58 |
|
Will this work? $file = strtr($file, '\\', '/');
foreach ($this->collapsePaths as $path) {
$path = strtr($path, '\\', '/');
$length = strlen($path);
if (strncmp($file, $path, $length) === 0 && (!isset($file[$length]) || $file[$length] === '/')) {
return TRUE;
}
}
return FALSE;Another rewrite (PHP compares first lengths of strings -> the char by char comparison is done only once) $file = strtr($file, '\\', '/');
foreach ($this->collapsePaths as $path) {
$path = strtr($path, '\\', '/');
if ($file === $path || strncmp($file, "$path/", strlen($path) + 1) === 0) {
return TRUE;
}
}
return FALSE; |
9a5274e to
cbbc3c2
Compare
That is not necessarily true, because of the stat cache and since these are paths from where source codes were probably loaded (if not using opcache), the information might have already been loaded.
But of course if we can avoid the chance, it's better. I think it will work (I can't come up with a situation where your solution won't work), so I updated the PR, thanks! 👍 |
|
What about simple if (strncmp("$file/", "$path/", strlen($path) + 1) === 0) { |
|
Yes, that would work too, but I think current solution is more readable, so it is up to you, if you want to do this microoptimalization. |
|
@dg 👍 |
e8be759 to
13f9a7b
Compare
|
|
|
With the submitted if ($file === $path || strncmp($file, "$path/", strlen($path) + 1) === 0) {version, this wouldn't be the issue, would it? Is the "faster" version worth it? |
|
Sry, it is not BC break. |
|
Yea, you are right :) Thanks for merging! |
Right now there is possibility to configure collapsed paths in BlueScreen with
BlueScreen::$collapsePaths. Since the name of the property contains "paths" I think all paths should be allowed.But because in the implementation a
/is added at the end, file paths never match. Adding/at the end is fine (actually necessary, because otherwise there will be false positives for dirs - I have added a test for this). With files there is of course similar issue with false positives, so matching must be done "exactly" (not starts with).So implementations for dirs and files must differ and I've not come up with a different solution (without an API change) other than checking the actual given path if it is a file or directory. I hope that should not be a problem.