| @@ -119,8 +119,13 @@ | ||
| 119 | 119 | public function get_columns_definition() { |
| 120 | 120 | return [ |
| 121 | 121 | 'ID BIGINT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY', |
| 122 | 122 | 'form_id BIGINT(20) UNSIGNED', |
| 123 | + // NOT NULL DEFAULT 0 is load-bearing, not tidiness. An anonymous | |
| 124 | + // submission stores 0, and Forms_Data::calculate_form_metrics() excludes | |
| 125 | + // site editors with `user_id NOT IN (…)`. NOT IN never matches NULL, so | |
| 126 | + // making this column nullable would drop every anonymous entry from the | |
| 127 | + // numerator and report a conversion rate near 0% on every form. | |
| 123 | 128 | 'user_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0', |
| 124 | 129 | 'form_data LONGTEXT', // Note: @since 0.0.13 -- We have renamed `user_data` column to `form_data`. |
| 125 | 130 | 'logs LONGTEXT', |
| 126 | 131 | 'notes LONGTEXT', |
| @@ -132,8 +137,14 @@ | ||
| 132 | 137 | 'updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
| 133 | 138 | 'INDEX idx_form_id (form_id)', // Indexing for the performance improvements. |
| 134 | 139 | 'INDEX idx_user_id (user_id)', |
| 135 | 140 | 'INDEX idx_form_id_created_at_status (form_id, created_at, status)', // Composite index for performance improvements. |
| 141 | + // Leads on the two columns Forms_Data::get_editing_submitter_ids() | |
| 142 | + // filters. idx_user_id alone cannot serve it -- created_at is not in it, | |
| 143 | + // and no other index leads on created_at -- so that lookup was a range | |
| 144 | + // scan with a row read per row plus a temp table for DISTINCT, on every | |
| 145 | + // Forms-list render. | |
| 146 | + 'INDEX idx_user_id_created_at (user_id, created_at)', | |
| 136 | 147 | ]; |
| 137 | 148 | } |
| 138 | 149 | |
| 139 | 150 | /** |
| @@ -145,8 +156,10 @@ | ||
| 145 | 156 | 'type VARCHAR(20) AFTER status', |
| 146 | 157 | 'extras LONGTEXT AFTER status', |
| 147 | 158 | 'user_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 AFTER form_id', |
| 148 | 159 | 'INDEX idx_user_id (user_id)', |
| 160 | + // Note: @since 2.12.7 -- Covers the conversion rate's submitter lookup. | |
| 161 | + 'INDEX idx_user_id_created_at (user_id, created_at)', | |
| 149 | 162 | ]; |
| 150 | 163 | } |
| 151 | 164 | |
| 152 | 165 | /** |
| @@ -542,9 +555,9 @@ | ||
| 542 | 555 | * @since 1.1.1 |
| 543 | 556 | * @return array<int> An array of form IDs. |
| 544 | 557 | */ |
| 545 | 558 | public static function get_form_ids_by_entries( $entry_ids ) { |
| 546 | - if ( empty( $entry_ids ) && ! is_array( $entry_ids ) ) { | |
| 559 | + if ( empty( $entry_ids ) || ! is_array( $entry_ids ) ) { | |
| 547 | 560 | return []; |
| 548 | 561 | } |
| 549 | 562 | |
| 550 | 563 | $results = self::get_instance()->get_results( |