Skip to content
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

fix (performance): performance optimizations #2836

Merged
merged 47 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6374c2d
removed v1 backward compatibility
Aug 8, 2023
710d04f
don't load proton compatibility functions if Jetpack proton is not pr…
Aug 8, 2023
598d946
save an option lookup if not needed
Aug 8, 2023
e04e6ba
only run filter when block is present
Aug 8, 2023
21a41ed
improve performance by removing some regex usage
Aug 8, 2023
41d96f2
optimize global settings to add hook only when the option is set
Aug 8, 2023
1d81907
removed some regex to improve performance
Aug 8, 2023
c4be72d
only do script_loader_tag if the font awesome kit
Aug 8, 2023
8080f0f
Do not always load v2 compatibility
Aug 8, 2023
0799fe9
the temp CPT for default blocks should only be done in the backend
Aug 8, 2023
4c7556c
Only do global styles if the correct option is set
Aug 8, 2023
a8e3739
only try to load polyfill accordion block when the accordion block is…
Aug 8, 2023
57e4561
enqueue the fonts only if we have fonts
Aug 8, 2023
359a9e8
optimize lightbox frontend loading
Aug 8, 2023
811281f
fixed PHP error
Aug 8, 2023
86341d8
fixed PHP errors
Aug 8, 2023
1112426
check if gutenberg constant first before adding the hook
Aug 8, 2023
7af70e7
Merge branch 'develop' into feat/memory-performance
Aug 8, 2023
350bd23
Merge branch 'develop' into feat/memory-performance
Aug 8, 2023
d02307c
only enqueue in the admin when the editor is used
Aug 9, 2023
afc09ec
enqueue the nodep styles along with the other styles
Aug 9, 2023
99b2d92
optimizing inline css should only be done in the frontend
Aug 9, 2023
1606bab
better loading of v2 optimization setting
Aug 9, 2023
0ce482f
global styles only in the frontend
Aug 9, 2023
f48304d
only load translations in the backend
Aug 9, 2023
0b053fd
enqueue better in the admin
Aug 9, 2023
6eb585f
fixed: incorrect callback resulting in many instances of Stackable_Po…
Aug 9, 2023
71543ea
remove unused welcome help modal
Aug 9, 2023
111cc9a
show_pro_notice_option is only for the rest api
Aug 9, 2023
e7afe44
don't load v2 settings if not used
Aug 9, 2023
c3872b0
stackable_v2_compatibility_option doesn't need to be in admin_init
Aug 9, 2023
30cf758
do not add the hook if missing query vars
Aug 9, 2023
052516f
reorder if conditions for faster execution
Aug 9, 2023
581c47d
bring back admin_init
Aug 9, 2023
2265c13
only save optimized css when needed
Aug 9, 2023
79bf4ad
don't get css raw
Aug 9, 2023
dc91248
only add the v2 render block filter only if v2 compatibility is enabled
Aug 11, 2023
10796b2
only load global settings hooks in the frontend
Aug 11, 2023
d7185a3
cleanup hook calling
Aug 11, 2023
e22679e
only load admin files if in the admin
Aug 11, 2023
d68089b
only require frontend loader PHP scripts when in the frontend
Aug 11, 2023
a67d0cc
combine multiple settings fetch into a single fetch
Aug 13, 2023
6192b22
Merge branch 'develop' into feat/memory-performance
Aug 17, 2023
2d269c3
undo unnecessary change
Aug 17, 2023
9608b90
fixed css loading order
Aug 17, 2023
b821170
fixed ordered loading of css
Aug 17, 2023
b2eaf75
Merge branch 'develop' into feat/memory-performance
Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,9 @@ gulp.task( 'style-deprecated-v2', function() {
.pipe( gulp.dest( 'dist/deprecated/' ) )
} )

gulp.task( 'style-deprecated-v1', function() {
return gulp.src( [ path.resolve( __dirname, './src/deprecated/v1/*.scss' ) ] )
.pipe( sass( deprecatedV2SassOptions ).on( 'error', sass.logError ) )
.pipe( concat( 'frontend_blocks_deprecated.css' ) )
.pipe( postcss( postCSSOptions ) )
.pipe( gulp.dest( 'dist/deprecated/' ) )
} )

gulp.task( 'style-deprecated', gulp.parallel(
'style-editor-deprecated-v2',
'style-deprecated-v2',
'style-deprecated-v1',
) )

/*********************************************************************
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ module.exports = {
'/node_modules/',
'<rootDir>/pro__premium_only/',
'/src/block',
'/help/__test__/videos.test.js',
],
}
58 changes: 31 additions & 27 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ function stackable_early_version_upgrade_check() {
*/
if ( ! function_exists( 'stackable_notice_gutenberg_plugin_activated' ) ) {
function stackable_notice_gutenberg_plugin_activated() {
global $wp_version;
if ( version_compare( $wp_version, '5.0', '>=' ) && is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
$ignore = get_option( 'stackable_notice_gutenberg_plugin_ignore' );
if ( ! $ignore ) {
printf(
Expand All @@ -141,7 +140,10 @@ function stackable_notice_gutenberg_plugin_activated() {
}
}
}
add_action( 'admin_notices', 'stackable_notice_gutenberg_plugin_activated' );

if ( defined( 'GUTENBERG_VERSION' ) ) {
add_action( 'admin_notices', 'stackable_notice_gutenberg_plugin_activated' );
}
}

if ( ! function_exists( 'stackable_notice_gutenberg_plugin_ignore' ) ) {
Expand Down Expand Up @@ -198,41 +200,44 @@ function stackable_deactivation_cleanup() {
require_once( plugin_dir_path( __FILE__ ) . 'src/icons.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/posts/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/pro.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/help/welcome-tutorial-video.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/jetpack.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/multisite.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/dynamic-breakpoints.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/design-library/init.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/global-settings.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/custom-block-styles.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/css-optimize.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/lightbox/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/compatibility/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/accordion/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/carousel/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/count-up/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/countdown/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/expand/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/notification/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/video-popup/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/table-of-contents/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/map/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/progress-bar/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/progress-circle/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/horizontal-scroller/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/tabs/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block-components/alignment/index.php' );
if ( ! is_admin() ) {
require_once( plugin_dir_path( __FILE__ ) . 'src/lightbox/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/accordion/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/carousel/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/count-up/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/countdown/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/expand/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/notification/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/video-popup/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/table-of-contents/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/map/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/progress-bar/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/progress-circle/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/horizontal-scroller/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block/tabs/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/block-components/alignment/index.php' );
}

/**
* Welcome screen.
*/
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/news.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/freemius.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/updates.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/wizard.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/notification.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/notification-rate.php' );
if ( is_admin() ) {
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/index.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/news.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/freemius.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/updates.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/wizard.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/notification.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/welcome/notification-rate.php' );
}

if ( sugb_fs()->is__premium_only() ) {
if ( STACKABLE_BUILD === 'premium' ) {
Expand All @@ -251,7 +256,6 @@ function stackable_deactivation_cleanup() {
/**
* V2 Deprecated
*/
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/v1/init.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/v2/init.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/v2/blocks.php' );
require_once( plugin_dir_path( __FILE__ ) . 'src/deprecated/v2/disabled-blocks.php' );
Expand Down
2 changes: 1 addition & 1 deletion src/block/accordion/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ function stackable_load_accordion_frontend_polyfill_script() {
);
}
}
add_action( 'wp_footer', 'stackable_load_accordion_frontend_polyfill_script' );
add_action( 'stackable/accordion/enqueue_scripts', 'stackable_load_accordion_frontend_polyfill_script' );
}
12 changes: 6 additions & 6 deletions src/block/posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function register_rest_fields() {
// Feature image urls.
register_rest_field( $post_type, 'featured_image_urls',
array(
'get_callback' => array( new Stackable_Posts_Block(), 'get_featured_image_urls' ),
'get_callback' => array( 'Stackable_Posts_Block', 'get_featured_image_urls' ),
'update_callback' => null,
'schema' => array(
'description' => __( 'Different sized featured images', STACKABLE_I18N ),
Expand All @@ -235,7 +235,7 @@ public function register_rest_fields() {
// Excerpt.
register_rest_field( $post_type, 'post_excerpt_stackable',
array(
'get_callback' => array( new Stackable_Posts_Block(), 'get_excerpt' ),
'get_callback' => array( 'Stackable_Posts_Block', 'get_excerpt' ),
'update_callback' => null,
'schema' => array(
'description' => __( 'Post excerpt for Stackable', STACKABLE_I18N ),
Expand All @@ -247,7 +247,7 @@ public function register_rest_fields() {
// Category links.
register_rest_field( $post_type, 'category_list',
array(
'get_callback' => array( new Stackable_Posts_Block(), 'get_category_list' ),
'get_callback' => array( 'Stackable_Posts_Block', 'get_category_list' ),
'update_callback' => null,
'schema' => array(
'description' => __( 'Category list links', STACKABLE_I18N ),
Expand All @@ -259,7 +259,7 @@ public function register_rest_fields() {
// Author name.
register_rest_field( $post_type, 'author_info',
array(
'get_callback' => array( new Stackable_Posts_Block(), 'get_author_info' ),
'get_callback' => array( 'Stackable_Posts_Block', 'get_author_info' ),
'update_callback' => null,
'schema' => array(
'description' => __( 'Author information', STACKABLE_I18N ),
Expand All @@ -272,7 +272,7 @@ public function register_rest_fields() {
register_rest_field( $post_type, 'comments_num',
array(
'get_callback' => 'stackable_commments_number_v2',
'get_callback' => array( new Stackable_Posts_Block(), 'get_comments_number' ),
'get_callback' => array( 'Stackable_Posts_Block', 'get_comments_number' ),
'update_callback' => null,
'schema' => array(
'description' => __( 'Number of comments', STACKABLE_I18N ),
Expand All @@ -284,7 +284,7 @@ public function register_rest_fields() {
// API endpoint for getting all the terms/taxonomies.
register_rest_route( 'stackable/v3', '/terms', array(
'methods' => 'GET',
'callback' => array( new Stackable_Posts_Block(), 'get_terms' ),
'callback' => array( 'Stackable_Posts_Block', 'get_terms' ),
'permission_callback' => function () {
return current_user_can( 'edit_posts' );
},
Expand Down
10 changes: 4 additions & 6 deletions src/components/base-control2/label-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* Internal dependencies
*/
import HelpTooltip from '../help-tooltip'
import { fetchSettings } from '~stackable/util'

/**
* WordPress dependencies
*/
import {
useRef, useState, useEffect,
} from '@wordpress/element'
import { loadPromise, models } from '@wordpress/api'
import { models } from '@wordpress/api'
import domReady from '@wordpress/dom-ready'

const LabelTooltip = props => {
Expand Down Expand Up @@ -109,11 +110,8 @@ let helpTooltipEnabled = true // Initial value, this will be updated on load.

// At the start, get whether the helpTooltips are enabled or disabled.
domReady( () => {
loadPromise.then( () => {
const settings = new models.Settings()
settings.fetch().then( response => {
helpTooltipEnabled = ! response.stackable_help_tooltip_disabled
} )
fetchSettings().then( response => {
helpTooltipEnabled = ! response.stackable_help_tooltip_disabled
} ).catch( () => {} )
} )

Expand Down
1 change: 0 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export { default as CodeTextarea } from './code-textarea'
export { default as CodeTextareaControl } from './code-textarea-control'
export { default as ConvertToContainerButton } from './convert-to-container-buttons'
export { default as GetBlockAttributesButton } from './block-attributes-get-button'
export { default as ModalWelcomeTutorial } from './modal-welcome-tutorial'
export { default as ModalDesignLibrary } from './modal-design-library'
export { default as AdminBaseSetting } from './admin-base-setting'
export { default as AdminTextSetting } from './admin-text-setting'
Expand Down
23 changes: 0 additions & 23 deletions src/components/modal-welcome-tutorial/__test__/index.test.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/components/modal-welcome-tutorial/editor.scss

This file was deleted.

42 changes: 0 additions & 42 deletions src/components/modal-welcome-tutorial/index.js

This file was deleted.

21 changes: 15 additions & 6 deletions src/css-optimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function __construct() {
// Only do this when inline style optimization is enabled.
// If stackable_optimize_inline_css === false (or option isn't
// present), that's the default value (true) for the option.
if ( get_option( 'stackable_optimize_inline_css' ) !== '' ) {
if ( ! is_admin() && get_option( 'stackable_optimize_inline_css' ) !== '' ) {
// Load the optimized CSS in the head of posts.
add_action( 'wp', array( $this, 'load_cached_css_for_post' ) );

Expand Down Expand Up @@ -112,6 +112,13 @@ public function generate_optimied_css_for_post( $post_id, $post, $update ) {
return;
}

$current_optimized_css = get_post_meta( $post_id, 'stackable_optimized_css', true );

// If no contents, don't do anything.
if ( empty( $post->post_content ) && empty( $optimized_css ) ) {
return;
}

// Convert content to blocks.
$blocks = parse_blocks( $post->post_content );

Expand All @@ -126,11 +133,13 @@ public function generate_optimied_css_for_post( $post_id, $post, $update ) {
$styles_only[] = $block_style[1];
}
}
$optimized_css = self::generate_css( $styles_only );
$optimized_css = count( $styles_only ) ? self::generate_css( $styles_only ) : '';

// Save the optimized CSS to the post.
update_post_meta( $post_id, 'stackable_optimized_css', $optimized_css );
update_post_meta( $post_id, 'stackable_optimized_css_raw', $styles );
// Save the optimized CSS to the post if it changed.
if ( ! empty( $current_optimized_css ) && $current_optimized_css !== $optimized_css ) {
update_post_meta( $post_id, 'stackable_optimized_css', $optimized_css );
update_post_meta( $post_id, 'stackable_optimized_css_raw', $styles );
}
}

/**
Expand Down Expand Up @@ -202,9 +211,9 @@ public function load_cached_css_for_post() {
if ( is_singular() && ! is_preview() && ! is_attachment() ) {
$post_id = get_the_ID();
$this->optimized_css = get_post_meta( $post_id, 'stackable_optimized_css', true );
$this->css_raw = get_post_meta( $post_id, 'stackable_optimized_css_raw', true );

if ( ! empty( $this->optimized_css ) ) {
$this->css_raw = get_post_meta( $post_id, 'stackable_optimized_css_raw', true );
add_action( 'wp_head', array( $this, 'print_optimized_styles' ) );
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/custom-block-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ function __construct() {

// We allow editing of default blocks in their own editor, we do
// this by creating a "dummy" CPT that we'll edit.
add_action( 'init', array( $this, 'register_temp_block_editor' ) );
add_action( 'admin_init', array( $this, 'register_temp_block_editor' ) );
add_action( 'rest_api_init', array( $this, 'register_temp_block_editor' ) );

// Disallow going through the list of all "dummy" CPTs.
add_action( 'current_screen', array( $this, 'temp_block_editor_list_disallow' ) );

// This will trigger the editor to redirect to the editor for a
// default block.
add_action( 'admin_init', array( $this, 'edit_default_block_redirect' ) );
if ( isset( $_REQUEST['stk_edit_block_style'] ) && isset( $_REQUEST['stk_edit_block'] ) && isset( $_REQUEST['stk_edit_block_title'] ) ) {
add_action( 'admin_init', array( $this, 'edit_default_block_redirect' ) );
}
}

/**
Expand Down Expand Up @@ -350,10 +353,6 @@ public function temp_block_editor_list_disallow() {
* @return void
*/
public function edit_default_block_redirect() {
if ( ! isset( $_REQUEST['stk_edit_block_style'] ) || ! isset( $_REQUEST['stk_edit_block'] ) || ! isset( $_REQUEST['stk_edit_block_title'] ) ) {
return;
}

$block_name = sanitize_text_field( $_REQUEST['stk_edit_block'] );
$style_slug = sanitize_text_field( $_REQUEST['stk_edit_block_style'] );
$block_title = sanitize_text_field( $_REQUEST['stk_edit_block_title'] );
Expand Down
Loading
Loading