-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Extensions - Limit depth of search for "info.xml" #24491
Conversation
(Standard links)
|
Thanks very much @totten for taking my comments on board. Asking because I do not know, what is the reason for searching for extensions in directories other than just these two? |
Well, basically because they were already being searched.... But more specifically:
(EDIT) So the overall effect here is to reduce depth of search and to skip some of the larger civicrm-core folders ( |
I just did a quick check & got this path
|
Also - my understanding is there is already a way to opt out |
@eileenmcnaughton To clarify:
So regarding
|
Yeah... on configurability, the substance of I think it's OK to do another issue/discussion/update about configuring the search-list. The option to limit depth remains useful(+simple) either way:
(It's fine to say "We don't put extensions in |
CRM/Utils/File.php
Outdated
@@ -753,6 +757,7 @@ public static function findFiles($dir, $pattern, $relative = FALSE) { | |||
: '@' . preg_quote(DIRECTORY_SEPARATOR) . '\.@'; | |||
|
|||
$dir = rtrim($dir, '/'); | |||
$baseDepth = substr_count($dir, '/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this PR does proceed, this would give a random number between 0, and, say, 16, on windows. On a typical install civicrm root looks like C:/path/to/drupal\sites\all\modules\civicrm\
, and of course sometimes people edit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demeritcowboy Yeah, I had meant to ping you about that. :)
I guess the only way out is through. Pushed a change that should work with both delimiters (while still keeping the string-operations minimal).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erm - sorry I wasn't trying to open a discussion about configuring the search list - my understanding is this IS existing functionality....
/**
* Which directories should we exclude when scanning the codebase for things
* like extension .info files, or .html partials or .xml files etc. This needs
* to be a valid preg_match() pattern.
*
* If you do not define it, a pattern that excludes dirs starting with a dot is
* used, e.g. to exclude .git/). Adding suitable patterns here can vastly speed
* up your container rebuilds and cache flushes. The pattern is matched against
* the absolute path. Remember to use your system's DIRECTORY_SEPARATOR the
* examples below assume /
*
* The default excludes node_modules (can be huge), various CiviCRM dirs that
* are unlikely to have anything we need to scan inside, and (what could be
* your) Drupal's private file storage area. It does not exclude
* vendor but you are likely to see an improvement by adding it.
*
* See https://docs.civicrm.org/sysadmin/en/latest/setup/optimizations/#exclude-dirs-that-do-not-need-to-be-scanned
* and also discussion on including vendor (excluded) in https://lab.civicrm.org/dev/core/-/issues/2031
*/
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && !defined('CIVICRM_EXCLUDE_DIRS_PATTERN')) {
define('CIVICRM_EXCLUDE_DIRS_PATTERN', '@/(\.|node_modules|js/|css/|bower_components|packages/|sites/default/files/private)@');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artfulrobot contributed that I believe
31514b6
to
ce8586a
Compare
CRM/Utils/File.php
Outdated
// They are roughly equivalent. (The differences are described by a secret book hidden in the tower of Mordor.) | ||
$depth = substr_count($path, '/'); | ||
if (DIRECTORY_SEPARATOR !== '/') { | ||
$depth += substr_count($path, PATH_SEPARATOR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be DIRECTORY_SEPARATOR instead of PATH.
But the bigger question is maybe who is going to use this setting, and, if it should exist, then could an upgrade script calculate what it should be based on the state of the system at the time (extensions get installed and uninstalled, but the depth is unlikely to increase except for a very weird extension).
Also I get an error if I set the setting to 2: Uncaught Error: Class 'Civi\Api4\Subscriber\AutocompleteSubscriber' not found in ...\ext\afform\core\afform.php:59
. So it suggests it shouldn't be allowed to be less than 3.
As noted it is a bit difficult to evaluate the effect. I'm not sure where efforts should focus. We have a couple suggestions scattered a bit:
- Serialize is slow
- The change in the class scanning PR.
- excessive cache clearing
- Does it need to scan anything (maybe it's convenient, but has a trade-off)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably this exclusion would still be in use.
Commenting because pinged by @eileenmcnaughton. @totten's proposal looks ok to me. I can't speak for those avanteguarde types who install extensions with composer, but thinking through the longest "reasonable" path.
So
Is that 3 levels deep (counting dirs) or 4 (counting dirs up to the file)? If three, and therefore would be found, I think that's fine. |
🤦 Fixed.
Yeah, that's still the same as before. IMHO, it's reasonable to have a global/crude policy to (eg) exclude (That doesn't mean max-depth should be a global/crude policy -- eg the contracts and de-facto practices are different for
Thanks, that's a good way to describe the subtlety. It's counting dirs. I agree with this target a "reasonable-long' . The example would match a filter of Is it better to describe the depth with or without the file? I'm not sure. FWIW, in Unix,
As Rich's example showed, the depth for So... the fewer people who need to use the setting, the better. It exists as a hedge or pressure-relief-valve. |
@totten Do you still have a commit sitting on your computer that didn't make it to the cloud? It still says PATH_SEPARATOR. |
@totten last comment seems to be the blocker |
ce8586a
to
1a9a7a0
Compare
1a9a7a0
to
97db4d2
Compare
Pushed up the missing fix re:PATH_SEPARATOR. I also added the pre-upgrade message. The message only appears if you have deeply nested extensions that would otherwise become unavailable. Here's how it looks in web UI and CLI when two extensions ( If you follow the instruction and reload, then the warning will clear up. |
jenkins retest this please (seems like a date rollover thing) |
Overview
This is an optimization that may slightly improve the performance of system-flushes. Specifically, it takes the largest file search (find
info.xml
files) and narrows it in a way that should still work on most deployments.This is follow-up to some of the side-chatter on #24490 (ping @agileware-justin).
Before
When scanning for
info.xml
files, Civi will consult:[civicrm.root]
)[civicrm.files]/ext
)vendor
(aka[cms.root]/vendor
)In each folder, it does an exhaustive search of the subtree.
After
When scanning for
info.xml
files, Civi will consult:[civicrm.root]/ext
)[civicrm.root]/tools
)[civicrm.files]/ext
)vendor
(aka[cms.root]/vendor
)In each folder, it will only search 3 levels deep.
Technical Details
On my local
dmaster
(D7; adhoc assortment of extensions), this reduces the number of directory-checks after a system-flush:I don't know a better way to measure the impact of this. Qualitatively, I expect the impact varies:
This arrangement should reduce the size of scans while still being drop-in compatible for most deployments -- even with some fairly esoteric customizations (e.g. implementers who deploy their own folder with a subtree of extensions; e.g. git repos with multiple extensions; e.g. Civi extensions installed via composer).
There are two main risks of incompatibility:
[civicrm.root]/my-extensions
. This would no longer be scanned. (You could move such a folder; eg to[civicrm.root]/ext/my-extensions
.)ext_max_depth
.)If this update is accepted, then we may also want to add a pre-upgrade check which performs the old scan and warns about any extensions that would be affected.(Updated) There is pre-upgrade check to warn about deeply nested extensions, e.g.