Ticket #3113: mythtv-CleanupRecordedTables-recordedmarkup_and_recordedseek-20070221.patch
File mythtv-CleanupRecordedTables-recordedmarkup_and_recordedseek-20070221.patch, 2.8 KB (added by , 17 years ago) |
---|
-
programs/mythbackend/housekeeper.cpp
362 362 "recordedprogram", 363 363 "recordedrating", 364 364 "recordedcredits", 365 "recordedmarkup", 366 "recordedseek", 365 367 "" }; // This blank entry must exist, do not remove. 366 368 QString table = tables[tableIndex]; 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 368 385 while (table != "") 369 386 { 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 370 407 query.prepare(QString("SELECT DISTINCT p.chanid, p.starttime " 371 "FROM %1 p LEFT JOIN recorded r " 408 "FROM temprecordedcleanup p " 409 "LEFT JOIN recorded r " 372 410 "ON p.chanid = r.chanid " 373 411 "AND p.starttime = r.progstart " 374 "WHERE r.chanid IS NULL;") 375 .arg(table)); 412 "WHERE r.chanid IS NULL;")); 376 413 if (!query.exec() || !query.isActive()) 377 414 { 378 415 MythContext::DBError("HouseKeeper Cleaning Recorded Tables", query); … … 393 430 tableIndex++; 394 431 table = tables[tableIndex]; 395 432 } 433 434 if (!query.exec("DROP TABLE temprecordedcleanup;")) 435 MythContext::DBError("Housekeeper Dropping Temporary Table", query); 436 396 437 } 397 438 398 439 void HouseKeeper::CleanupProgramListings(void)