| @@ -26,9 +26,9 @@ | ||
| 26 | 26 | self::setupChatHistoryTable(); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Get the last 150 messages | |
| 30 | + * Get the last 250 messages | |
| 31 | 31 | * |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | public static function getChatHistory($user_id = null) |
| @@ -38,9 +38,9 @@ | ||
| 38 | 38 | $user_id = $user_id ?: get_current_user_id(); |
| 39 | 39 | |
| 40 | 40 | $results = $wpdb->get_results( |
| 41 | 41 | $wpdb->prepare( |
| 42 | - "SELECT * FROM $table WHERE user_id = %d ORDER BY id DESC LIMIT 150", | |
| 42 | + "SELECT * FROM $table WHERE user_id = %d ORDER BY id DESC LIMIT 250", | |
| 43 | 43 | $user_id |
| 44 | 44 | ), |
| 45 | 45 | ARRAY_A |
| 46 | 46 | ); |
| @@ -114,10 +114,11 @@ | ||
| 114 | 114 | ); |
| 115 | 115 | $startIndex = 0; |
| 116 | 116 | if ($latest) { |
| 117 | 117 | foreach ($messages as $i => $msg) { |
| 118 | + // Tool results land on the newest row after insert; skipping it loses them. | |
| 118 | 119 | if ($msg['id'] === $latest) { |
| 119 | - $startIndex = $i + 1; | |
| 120 | + $startIndex = $i; | |
| 120 | 121 | break; |
| 121 | 122 | } |
| 122 | 123 | } |
| 123 | 124 | } |
| @@ -187,9 +188,10 @@ | ||
| 187 | 188 | $cols = []; |
| 188 | 189 | foreach ($columns as $name => $type) { |
| 189 | 190 | $cols[] = "$name $type"; |
| 190 | 191 | } |
| 191 | - $sql = "CREATE TABLE $table (" . implode(',', $cols) . ", INDEX(user_id))"; | |
| 192 | + $indexes = "INDEX(user_id), UNIQUE INDEX unique_event_id (event_id, user_id)"; | |
| 193 | + $sql = "CREATE TABLE $table (" . implode(',', $cols) . ", $indexes)"; | |
| 192 | 194 | $sql .= " " . $wpdb->get_charset_collate() . ";"; |
| 193 | 195 | $wpdb->query($sql); |
| 194 | 196 | return; |
| 195 | 197 | } |