Skip to content

Commit

Permalink
add QM loggging
Browse files Browse the repository at this point in the history
  • Loading branch information
trepmal committed Jul 2, 2024
1 parent 584db00 commit 3d010f4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
24 changes: 22 additions & 2 deletions cssconcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,46 @@ function do_items( $handles = false, $group = false ) {

// Don't try to concat styles which are loaded conditionally (like IE stuff)
if ( isset( $extra['conditional'] ) ) {
do_action( 'qm/vip_concat_info', sprintf( '[css] Skipped: %s. Reason: is conditional', $css_url ) );
$do_concat = false;
}

// Don't concat rtl stuff for now until concat supports it correctly
if ( 'rtl' === $this->text_direction && ! empty( $extra['rtl'] ) ) {
do_action( 'qm/vip_concat_info', sprintf( '[css] Skipped: %s. Reason: is rtl', $css_url ) );
$do_concat = false;
}

// Don't try to concat externally hosted scripts
$is_internal_url = WPCOM_Concat_Utils::is_internal_url( $css_url, $siteurl );
if ( ! $is_internal_url ) {
do_action( 'qm/vip_concat_info', sprintf( '[css] Skipped: %s. Reason: not internal url', $css_url ) );
$do_concat = false;
}

// Concat and canonicalize the paths only for
// existing scripts that aren't outside ABSPATH
$css_realpath = WPCOM_Concat_Utils::realpath( $css_url, $siteurl );
if ( ! $css_realpath || 0 !== strpos( $css_realpath, ABSPATH ) ) {
if ( $css_url ) {
// check for url reduces noise of inline styles
do_action( 'qm/vip_concat_info', sprintf( '[css] Skipped: %s. Reason: outside ABSPATH', $css_url ) );
}
$do_concat = false;
} else {
$css_url_parsed['path'] = substr( $css_realpath, strlen( ABSPATH ) - 1 );
}

// Allow plugins to disable concatenation of certain stylesheets.
$do_concat = apply_filters( 'css_do_concat', $do_concat, $handle );
$do_concat_after = apply_filters( 'css_do_concat', $do_concat, $handle );
if ( $do_concat && ! $do_concat_after ) {
do_action( 'qm/vip_concat_info', sprintf( '[css] Skipped: %s. Reason: filtered', $css_url ) );
}
$do_concat = $do_concat_after;

if ( true === $do_concat ) {
$media = $obj->args;
if( empty( $media ) ) {
if ( empty( $media ) ) {
$media = 'all';
}
if ( ! isset( $stylesheets[ $stylesheet_group_index ] ) || ( isset( $stylesheets[ $stylesheet_group_index ] ) && ! is_array( $stylesheets[ $stylesheet_group_index ] ) ) ) {
Expand Down Expand Up @@ -136,8 +147,16 @@ function do_items( $handles = false, $group = false ) {
}
}

$count = count( $paths );
if ( $count > 150 ) {
do_action( 'qm/vip_concat_warn', sprintf( '[css] TOO LARGE Bundle %s contains %d items: %s', $path_str, $count, "\n" . implode("\n", $paths ) ) );
} else {
do_action( 'qm/vip_concat_info', sprintf( '[css] Bundle %s contains %d items: %s', $path_str, $count, "\n" . implode("\n", $paths ) ) );
}

$href = $siteurl . "/_static/??" . $path_str;
} else {
do_action( 'qm/vip_concat_info', sprintf( '[css] Skipped: %s. Reason: lonely (nothing to concatenate with)', implode( $css ) ) );
$href = $this->cache_bust_mtime( $siteurl . current( $css ), $siteurl );
}

Expand Down Expand Up @@ -207,3 +226,4 @@ function css_concat_init() {
}

add_action( 'init', 'css_concat_init' );

17 changes: 16 additions & 1 deletion jsconcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,22 @@ function do_items( $handles = false, $group = false ) {
// Don't try to concat externally hosted scripts
$is_internal_url = WPCOM_Concat_Utils::is_internal_url( $js_url, $siteurl );
if ( ! $is_internal_url ) {
do_action( 'qm/vip_concat_info', sprintf( '[js] Skipped: %s. Reason: not internal URL', $js_url ) );
$do_concat = false;
}

// Concat and canonicalize the paths only for
// existing scripts that aren't outside ABSPATH
$js_realpath = WPCOM_Concat_Utils::realpath( $js_url, $siteurl );
if ( ! $js_realpath || 0 !== strpos( $js_realpath, ABSPATH ) ) {
do_action( 'qm/vip_concat_info', sprintf( '[js] Skipped: %s. Reason: outside ABSPATH', $js_url ) );
$do_concat = false;
} else {
$js_url_parsed['path'] = substr( $js_realpath, strlen( ABSPATH ) - 1 );
}

if ( $this->has_inline_content( $handle ) ) {
do_action( 'qm/vip_concat_info', sprintf( '[js] Skipped: %s. Reason: has inline content', $js_url ) );
$do_concat = false;
}

Expand All @@ -125,7 +128,11 @@ function do_items( $handles = false, $group = false ) {
}

// Allow plugins to disable concatenation of certain scripts.
$do_concat = apply_filters( 'js_do_concat', $do_concat, $handle );
$do_concat_after = apply_filters( 'js_do_concat', $do_concat, $handle );
if ( $do_concat && ! $do_concat_after ) {
do_action( 'qm/vip_concat_info', sprintf( '[js] Skipped: %s. Reason: filtered', $js_url ) );
}
$do_concat = $do_concat_after;

if ( true === $do_concat ) {
if ( !isset( $javascripts[$level] ) ) {
Expand Down Expand Up @@ -167,8 +174,16 @@ function do_items( $handles = false, $group = false ) {
$path_str = '-' . $path_64;
}

$count = count( $paths );
if ( $count > 150 ) {
do_action( 'qm/vip_concat_warn', sprintf( '[js] TOO LARGE Bundle %s contains %d items: %s', $path_str, $count, "\n" . implode("\n", $paths ) ) );
} else {
do_action( 'qm/vip_concat_info', sprintf( '[js] Bundle %s contains %d items: %s', $path_str, $count, "\n" . implode("\n", $paths ) ) );
}

$href = $siteurl . "/_static/??" . $path_str;
} elseif ( isset( $js_array['paths'] ) && is_array( $js_array['paths'] ) ) {
do_action( 'qm/vip_concat_info', sprintf( '[js] Skipped: %s. Reason: lonely (nothing to concatenate with)', implode( $js_array['paths'] ) ) );
$href = $this->cache_bust_mtime( $siteurl . $js_array['paths'][0], $siteurl );
}

Expand Down

0 comments on commit 3d010f4

Please sign in to comment.