Ticket #12451: optimizedb.diff

File optimizedb.diff, 2.4 KB (added by J.Pilk@…, 4 years ago)
  • .pl

    old new  
    22#
    33# Connects to the mythtv database and repairs/optimizes the tables that it
    44# finds.  Suggested use is to cron it to run once per day.
     5# Timing additions by JP following http://www.perlmonks.org/?node_id=795716
    56#
    67# @url       $URL$
    78# @date      $Date$
     
    1314# Includes
    1415    use DBI;
    1516    use MythTV;
     17    use Time::HiRes qw( time );  # If required
     18   
     19# Setup timing stuff
     20    my @t;
    1621
    1722# Connect to mythbackend
    1823    my $Myth = new MythTV({'connect' => 0});
     
    2227
    2328# Repair and optimize each table
    2429    foreach $table ($dbh->tables) {
     30        $t[0]= time();
     31        print "Working on: $table\n";
    2532        unless ($dbh->do("REPAIR TABLE $table")) {
    2633            print "Skipped:  $table\n";
    2734            next;
     
    3239        if ($dbh->do("ANALYZE TABLE $table")) {
    3340            print "Analyzed: $table\n";
    3441        }
     42    $t[1]= time();
     43    my $diff = formatted_time_diff(@t);
     44    print "Processing took $diff seconds\n";
    3545    }
    3646
    37 # Defragement seek table
     47# Defrag some big tables; see Ticket #12451   
     48
     49# Defragment seek table
     50    $t[0]= time();
     51    print "Defragging: recordedseek\n";
    3852    if ($dbh->do("ALTER TABLE `recordedseek` ORDER BY chanid, starttime, type")) {
    3953        print "Defragmented: recordedseek\n";
     54        $t[1]= time();
     55        my $diff = formatted_time_diff(@t);
     56        print "Processing took $diff seconds\n";       
    4057    }
    41 # Defragement program table
     58# Defragment program table
     59    $t[0]= time();
     60    print "Defragging: program\n";
    4261    if ($dbh->do("ALTER TABLE `program` ORDER BY starttime, chanid")) {
    4362        print "Defragmented: program\n";
     63        $t[1]= time();
     64        my $diff = formatted_time_diff(@t);
     65        print "Processing took $diff seconds\n";
    4466    }
    45 # Defragement video seek table
     67# Defragment video seek table
     68    $t[0]= time();
     69    print "Defragging: filemarkup\n";
    4670    if ($dbh->do("ALTER TABLE `filemarkup` ORDER BY filename")) {
    47         print "Defragmented: filemarkup\n";
     71       print "Defragmented: filemarkup\n";
     72       $t[1]= time();
     73       my $diff = formatted_time_diff(@t);
     74       print "Processing took $diff seconds\n";
    4875    }
    4976
     77# Format calculated time interval
     78
     79    sub formatted_time_diff {
     80       return sprintf("%.2f", $_[1]-$_[0])
     81    }