File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -139,20 +139,21 @@ public function trim() {
139
139
// Rename table and copy is over.
140
140
$ this ->connection ->exec ("ALTER TABLE " . $ table . " RENAME TO original_ " . $ table );
141
141
$ ignore [] = 'original_ ' . $ table ;
142
- $ this ->connection ->exec ("CREATE TABLE " . $ table . " SELECT * FROM original_ " . $ table );
143
142
// This makes assumptions about the primary key, should be configurable.
144
143
$ primary_key = $ this ->connection ->query ("SHOW KEYS FROM original_ " . $ table . " WHERE Key_name = 'PRIMARY' " )
145
144
->fetch ()['Column_name ' ];
146
145
if ($ primary_key ) {
146
+ $ keep = array ();
147
147
$ all = $ this ->connection ->query ("SELECT " . $ primary_key . " FROM " . $ table )
148
148
->fetchAll ();
149
149
foreach ($ all as $ key => $ row ) {
150
150
// Delete every other row.
151
151
if ($ key % 4 == 0 ) {
152
- continue ;
152
+ $ keep [] = $ row [ $ primary_key ] ;
153
153
}
154
- $ this ->connection ->exec ("DELETE FROM " . $ table . " WHERE " . $ primary_key . "= " . $ row [$ primary_key ]);
155
154
}
155
+ $ keep = implode (', ' , $ keep );
156
+ $ this ->connection ->exec ("CREATE TABLE " . $ table . " SELECT * FROM original_ " . $ table . 'WHERE ' . $ key . ' IN ( ' . $ keep . ') ' );
156
157
}
157
158
}
158
159
}
You can’t perform that action at this time.
0 commit comments