Repository navigation
Add a few optimizations #3264
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
Add a few optimizations #3264
Changes from all commits
d8a7c26
856192e
63c89cd
1d31a35
91eb91d
f2c89d4
278c82d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -292,6 +292,7 @@ private function create_tables() { | |||||||
| * @since 6.6 | ||||||||
| * @since 6.16.3 idx_form_id_is_draft was also added to frm_items. | ||||||||
| * @since 6.17 idx_form_id_type was also added to frm_fields. | ||||||||
| * @since x.x idx_form_id_created_at was added to frm_items, and idx_parent_form_id and frm_forms_template_status to frm_forms. | ||||||||
| * | ||||||||
| * @return void | ||||||||
| */ | ||||||||
|
|
@@ -326,6 +327,33 @@ private function add_composite_indexes() { | |||||||
| $wpdb->query( "CREATE INDEX idx_form_id_type ON `{$wpdb->prefix}frm_fields` (form_id, type(30))" ); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * The entry list sorts one form's entries by created_at, without filtering on is_draft. | ||||||||
| * KEY form_id alone cannot satisfy that ORDER BY, so the database read every matching row | ||||||||
| * and sorted it: on a form with 50,000 entries the first page took about 100ms. | ||||||||
| * | ||||||||
| * The is_draft column is deliberately left out. Putting it between form_id and created_at | ||||||||
| * leaves created_at unusable for the sort whenever is_draft is unconstrained, which is | ||||||||
| * exactly how the entry list queries. Draft filtering is served by idx_form_id_is_draft. | ||||||||
| */ | ||||||||
| $table_name = "{$wpdb->prefix}frm_items"; | ||||||||
| $index_name = 'idx_form_id_created_at'; | ||||||||
|
|
||||||||
| if ( ! self::index_exists( $table_name, $index_name ) ) { | ||||||||
| $wpdb->query( "CREATE INDEX idx_form_id_created_at ON `{$wpdb->prefix}frm_items` (form_id, created_at)" ); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Repeaters and embedded forms look their child forms up by parent_form_id, which had | ||||||||
| * no index at all, so every lookup was a full scan of frm_forms. | ||||||||
|
Comment on lines
+347
to
+348
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Present tense, no history ("which had no index at all" reads as a changelog).
Suggested change
|
||||||||
| */ | ||||||||
| $table_name = "{$wpdb->prefix}frm_forms"; | ||||||||
| $index_name = 'idx_parent_form_id'; | ||||||||
|
|
||||||||
| if ( ! self::index_exists( $table_name, $index_name ) ) { | ||||||||
| $wpdb->query( "CREATE INDEX idx_parent_form_id ON `{$wpdb->prefix}frm_forms` (parent_form_id)" ); | ||||||||
| } | ||||||||
|
|
||||||||
| $table_name = "{$wpdb->prefix}frm_forms"; | ||||||||
| $index_name = 'frm_forms_template_status'; | ||||||||
|
|
||||||||
|
|
||||||||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,7 +14,13 @@ public static function load_hooks() { | |||||||||||||
|
|
||||||||||||||
| add_filter( 'frm_payment_gateways', 'FrmPayPalLiteAppController::add_gateway' ); | ||||||||||||||
|
|
||||||||||||||
| add_action( 'init', 'FrmPayPalLiteConnectHelper::check_for_redirects' ); | ||||||||||||||
| // Only hook this up on the OAuth return request. Registering it unconditionally made | ||||||||||||||
| // WordPress autoload FrmPayPalLiteConnectHelper on every front end page view. | ||||||||||||||
| // Paired with FrmPayPalLiteConnectHelper::user_landed_on_the_oauth_return_url, which | ||||||||||||||
| // checks the same query argument. | ||||||||||||||
|
Comment on lines
+17
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Registering it unconditionally made WordPress autoload…" narrates what used to happen. Same wording is in the Square and Stripe controllers. State the present fact:
Suggested change
|
||||||||||||||
| if ( isset( $_GET['frm_paypal_api_return_oauth'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||||||||||||||
| add_action( 'init', 'FrmPayPalLiteConnectHelper::check_for_redirects' ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Use 20 so this happens after the Stripe add-on. | ||||||||||||||
| add_filter( 'frm_pro_show_card_callback', 'FrmPayPalLiteActionsController::maybe_show_card', 20, 2 ); | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,12 @@ public static function load_hooks() { | |
| // Actions. | ||
| add_action( 'frm_entry_form', 'FrmStrpLiteAuth::add_hidden_token_field' ); | ||
| add_action( 'frm_enqueue_form_scripts', 'FrmStrpLiteActionsController::maybe_load_scripts' ); | ||
| add_action( 'init', 'FrmStrpLiteConnectHelper::check_for_stripe_connect_webhooks' ); | ||
|
|
||
| // Only hook this up on requests it can act on. Registering it unconditionally made | ||
| // WordPress autoload FrmStrpLiteConnectHelper on every front end page view. | ||
| if ( self::request_may_be_for_stripe_connect() ) { | ||
| add_action( 'init', 'FrmStrpLiteConnectHelper::check_for_stripe_connect_webhooks' ); | ||
| } | ||
|
|
||
| // Filters. | ||
| add_filter( 'frm_saved_errors', 'FrmStrpLiteAppController::maybe_add_payment_error', 10, 2 ); | ||
|
|
@@ -52,6 +57,24 @@ function ( $form_col ) { | |
| add_action( 'frm_form_classes', 'FrmStrpLiteLinkController::add_form_classes' ); | ||
| } | ||
|
|
||
| /** | ||
| * Could this request be a Stripe Connect return trip or one of the Connect AJAX actions? | ||
| * | ||
| * Used to keep FrmStrpLiteConnectHelper out of ordinary page views. The helper still runs | ||
| * its own narrower checks, this only decides whether it is worth loading at all. | ||
| * | ||
| * @since x.x | ||
| * | ||
| * @return bool | ||
| */ | ||
| private static function request_may_be_for_stripe_connect() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // These two query arguments are also checked in FrmStrpLiteConnectHelper, by | ||
| // user_landed_on_the_return_url and user_landed_on_the_oauth_return_url. | ||
| // phpcs:disable WordPress.Security.NonceVerification.Recommended | ||
| return wp_doing_ajax() || isset( $_GET['frm_stripe_connect_return'] ) || isset( $_GET['frm_stripe_connect_return_oauth'] ); | ||
| // phpcs:enable WordPress.Security.NonceVerification.Recommended | ||
| } | ||
|
|
||
| /** | ||
| * @return void | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,7 +252,7 @@ public function test_sanitize_request() { | |
| } | ||
|
|
||
| public function test_kses() { | ||
| $start_value = '<script><script>'; | ||
| $start_value = '<script></script><script></script>'; | ||
| $safe_value = 'Hello, <a href="/test">click here</a>'; | ||
| $start_value .= $safe_value; | ||
| $stripped_value = FrmAppHelper::kses( $start_value ); | ||
|
|
@@ -264,34 +264,36 @@ public function test_kses() { | |
|
|
||
| public function test_kses_submit_button() { | ||
| $default_submit_button_html = '<div class="frm_submit"> | ||
| [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] | ||
| [if back_button]<button class="frm_prev_page" [back_hook] formnovalidate="formnovalidate" name="frm_prev_page" type="submit">[back_label]</button>[/if back_button] | ||
| <button class="frm_button_submit" type="submit" [button_action]>[button_label]</button> | ||
| [if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft] | ||
| [if save_draft]<a class="frm_save_draft" [draft_hook] href="#" tabindex="0">[draft_label]</a>[/if save_draft] | ||
| </div>'; | ||
| $this->assertSame( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $default_submit_button_html, | ||
| FrmAppHelper::kses_submit_button( $default_submit_button_html ) | ||
| ); | ||
|
|
||
| $with_custom_class = '<div class="frm_submit"> | ||
| [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] | ||
| [if back_button]<button class="frm_prev_page" [back_hook] formnovalidate="formnovalidate" name="frm_prev_page" type="submit">[back_label]</button>[/if back_button] | ||
| <button class="frm_button_submit frm_inline_submit" type="submit" [button_action]>[button_label]</button> | ||
| [if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft] | ||
| [if save_draft]<a class="frm_save_draft" [draft_hook] href="#" tabindex="0">[draft_label]</a>[/if save_draft] | ||
| </div>'; | ||
| $this->assertSame( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $with_custom_class, | ||
| FrmAppHelper::kses_submit_button( $with_custom_class ) | ||
| ); | ||
|
|
||
| $previous_default_html = '<div class="frm_submit"> | ||
| [if back_button]<input type="button" value="[back_label]" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook] />[/if back_button] | ||
| [if back_button]<input class="frm_prev_page" [back_hook] formnovalidate="formnovalidate" name="frm_prev_page" type="button" value="[back_label]" />[/if back_button] | ||
| <input type="submit" value="[button_label]" [button_action] /> | ||
| <img class="frm_ajax_loading" src="[frmurl]/images/ajax_loader.gif" alt="Sending" style="visibility:hidden" /> | ||
| <img alt="Sending" class="frm_ajax_loading" src="[frmurl]/images/ajax_loader.gif" style="visibility:hidden" /> | ||
| [if save_draft]<a class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft] | ||
| </div>'; | ||
| // Since WordPress 7.2, wp_kses drops the self-closing slash from void tags. | ||
| $this->assertSame( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $previous_default_html, | ||
| FrmAppHelper::kses_submit_button( $previous_default_html ) | ||
| str_replace( ' />', '>', $previous_default_html ), | ||
| str_replace( ' />', '>', FrmAppHelper::kses_submit_button( $previous_default_html ) ), | ||
| 'The legacy submit button HTML should keep its shortcodes.' | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -305,10 +307,10 @@ public function test_kses_icon() { | |
| $icon = '<svg class="frmsvg frm_zapier_icon frm_show_upgrade" style="--primary-700:#efefef"><use href="#frm_zapier_icon" /></svg>'; | ||
| $this->assertSame( $icon, FrmAppHelper::kses_icon( $icon ) ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| $icon = '<svg class="frmsvg frm_more_horiz_solid_icon frm-show-inline-modal" data-open="frm-layout-classes-box" title="Toggle Options" tabindex="0"><use href="#frm_more_horiz_solid_icon" /></svg>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | ||
| $icon = '<svg class="frmsvg frm_more_horiz_solid_icon frm-show-inline-modal" data-open="frm-layout-classes-box" tabindex="0" title="Toggle Options"><use href="#frm_more_horiz_solid_icon" /></svg>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | ||
| $this->assertSame( $icon, FrmAppHelper::kses_icon( $icon ) ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| $icon = '<svg class="frmsvg" aria-label="WordPress" style="width:90px;height:90px"><use href="#frm_wordpress_icon" /></svg>'; | ||
| $icon = '<svg aria-label="WordPress" class="frmsvg" style="width:90px;height:90px"><use href="#frm_wordpress_icon" /></svg>'; | ||
| $this->assertSame( $icon, FrmAppHelper::kses_icon( $icon ) ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,9 @@ public function test_sidebar_referrer_preserves_line_breaks() { | |
| } finally { | ||
| ob_end_clean(); | ||
| } | ||
| $this->assertStringContainsString( "https://example.com/<br />\n<img src=x onerror=alert(1)><br />\r\nLast line", $html ); | ||
| // Since WordPress 7.2, wp_kses outputs <br> and converts CRLF line endings to LF. | ||
| $expected = wp_kses( "https://example.com/<br />\n<img src=x onerror=alert(1)><br />\r\nLast line", array( 'br' => array() ) ); | ||
| $this->assertStringContainsString( $expected, $html ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $this->assertStringNotContainsString( '<img src=x', $html ); | ||
| } | ||
| } | ||
|
|
||
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.
State the fact, not the benchmark. A measured timing narrates an event and goes stale; the second paragraph is the useful gotcha, so keep that.