I didn't really look in the code but thinking this query here only needs to be executed when an action custom dimension is used: https://github.com/matomo-org/matomo/blob/4.1.1/plugins/CustomDimensions/Tracker/CustomDimensionsRequestProcessor.php#L49-L51
Not sure it's used for visit custom dimension as a time spent on one action wouldn't be that useful? If I see this right then we shouldn't execute it if only visit custom dimensions are used.
Not sure if time_spent
is used in any other way.
actually this is already done. just the method name was not clear