| @@ -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 | } |