367 | | |
| 369 | |
| 370 | // Because recordedseek can have millions of rows, we don't want to JOIN it |
| 371 | // with recorded. Instead, pull out DISTINCT chanid and starttime into a |
| 372 | // temporary table (resulting in tens, hundreds, or--at most--a few |
| 373 | // thousand rows) for the JOIN |
| 374 | QString querystr; |
| 375 | querystr = "CREATE TEMPORARY TABLE IF NOT EXISTS temprecordedcleanup (" |
| 376 | "chanid int(10) unsigned NOT NULL default '0'," |
| 377 | "starttime datetime NOT NULL default '0000-00-00 00:00:00' );"; |
| 378 | |
| 379 | if (!query.exec(querystr)) |
| 380 | { |
| 381 | MythContext::DBError("Housekeeper Creating Temporary Table", query); |
| 382 | return; |
| 383 | } |
| 384 | |
| 387 | query.prepare(QString("TRUNCATE TABLE temprecordedcleanup;")); |
| 388 | if (!query.exec() || !query.isActive()) |
| 389 | { |
| 390 | MythContext::DBError("Housekeeper Truncating Temporary Table", |
| 391 | query); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | query.prepare(QString("INSERT INTO temprecordedcleanup " |
| 396 | "( chanid, starttime ) " |
| 397 | "SELECT DISTINCT chanid, starttime " |
| 398 | "FROM %1;") |
| 399 | .arg(table)); |
| 400 | |
| 401 | if (!query.exec() || !query.isActive()) |
| 402 | { |
| 403 | MythContext::DBError("HouseKeeper Cleaning Recorded Tables", query); |
| 404 | return; |
| 405 | } |
| 406 | |