[MTOS-dev] [movabletype] bchoate, r1523: New concatenated indexes. Schema bump to...

Brad Choate brad at sixapart.com
Thu Mar 13 14:23:40 PDT 2008


Sure. Prior to MT 4.1, the MT object schema never supported the  
declaration of concatenated indexes. Meaning, creating an index on two  
or more columns. Now that we can declare these, we're making use of  
them, since it makes a big difference for the larger MT installations.  
So yes, it is significant, if you have lots of blogs with lots of  
entries.

-Brad


On Mar 13, 2008, at 2:03 PM, Timothy Appnel wrote:

> This looks like an interesting commit. Its not clear what these
> changes are doing though. Could someone (brad?) clue us in on this
> one? Seems like it could be important. Thanks. <tim/>
>
> On 3/13/08, commits at code.sixapart.com <commits at code.sixapart.com>  
> wrote:
>> New concatenated indexes. Schema bump to 4.0042
>>
>>
>> U   branches/release-31/build/mt-dists/default.mk
>> U   branches/release-31/lib/MT/Category.pm
>> U   branches/release-31/lib/MT/Comment.pm
>> U   branches/release-31/lib/MT/Entry.pm
>> U   branches/release-31/lib/MT/ObjectAsset.pm
>> U   branches/release-31/lib/MT/ObjectTag.pm
>> U   branches/release-31/lib/MT/Placement.pm
>> U   branches/release-31/lib/MT/TBPing.pm
>> U   branches/release-31/lib/MT/TemplateMap.pm
>>
>>
>> Modified: branches/release-31/build/mt-dists/default.mk
>> ===================================================================
>> --- branches/release-31/build/mt-dists/default.mk       2008-03-13  
>> 18:55:13 UTC (rev 1522)
>> +++ branches/release-31/build/mt-dists/default.mk       2008-03-13  
>> 18:55:27 UTC (rev 1523)
>> @@ -1,7 +1,7 @@
>>  PRODUCT_NAME = Movable Type Core
>>
>>  PRODUCT_VERSION = 4.2
>> -SCHEMA_VERSION = 4.0041
>> +SCHEMA_VERSION = 4.0042
>>  API_VERSION = 4.2
>>
>>  # BUILD_LANGUAGE = en_US
>>
>> Modified: branches/release-31/lib/MT/Category.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/Category.pm      2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/Category.pm      2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -28,6 +28,9 @@
>>         label => 1,
>>         parent => 1,
>>         basename => 1,
>> +        blog_class => {
>> +            columns => [ 'blog_id', 'class' ],
>> +        },
>>     },
>>     defaults => {
>>         parent => 0,
>>
>> Modified: branches/release-31/lib/MT/Comment.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/Comment.pm       2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/Comment.pm       2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -31,7 +31,12 @@
>>         ip => 1,
>>         created_on => 1,
>>         entry_id => 1,
>> -        blog_id => 1,
>> +        blog_stat => {
>> +            columns => [ 'blog_id', 'junk_status', 'created_on' ],
>> +        },
>> +        blog_visible => {
>> +            columns => [ 'blog_id', 'visible', 'created_on' ],
>> +        },
>>         email => 1,
>>         commenter_id => 1,
>>         visible => 1,
>> @@ -49,8 +54,8 @@
>>     primary_key => 'id',
>>  });
>>
>> -use constant JUNK => -1;
>> -use constant NOT_JUNK => 1;
>> +sub JUNK ()     { -1 }
>> +sub NOT_JUNK () { 1 }
>>
>>  my %blocklists = ();
>>
>> @@ -112,77 +117,24 @@
>>  sub _nextprev {
>>     my $obj = shift;
>>     my $class = ref($obj);
>> -    my ($direction, $publish_only) = @_;
>> +    my ($direction, $terms) = @_;
>>     return undef unless ($direction eq 'next' || $direction eq  
>> 'previous');
>>     my $next = $direction eq 'next';
>>
>>     my $label = '__' . $direction;
>> -    return $obj->{$label} if $obj->{$label};
>> -
>> -    # Selecting the adjacent object can be tricky since timestamps
>> -    # are not necessarily unique for entries. If we find that the
>> -    # next/previous object has a matching timestamp, keep  
>> selecting entries
>> -    # to select all entries with the same timestamp, then compare  
>> them using
>> -    # id as a secondary sort column.
>> -
>> -    my ($id, $ts) = ($obj->id, $obj->created_on);
>> -    my $iter = $class->load_iter({
>> -        blog_id => $obj->blog_id,
>> -        created_on => ($next ? [ $ts, undef ] : [ undef, $ts ]),
>> -        %{$publish_only}
>> -    }, {
>> -        'sort' => 'created_on',
>> -        'direction' => $next ? 'ascend' : 'descend',
>> -        'range_incl' => { 'created_on' => 1 },
>> -    });
>> -
>> -    # This selection should always succeed, but handle situation if
>> -    # it fails by returning undef.
>> -    return unless $iter;
>> -
>> -    # The 'same' array will hold any entries that have matching
>> -    # timestamps; we will then sort those by id to find the correct
>> -    # adjacent object.
>> -    my @same;
>> -    while (my $e = $iter->()) {
>> -        # Don't consider the object that is 'current'
>> -        next if $e->id == $id;
>> -        my $e_ts = $e->created_on;
>> -        if ($e_ts eq $ts) {
>> -            # An object with the same timestamp should only be
>> -            # considered if the id is in the scope we're looking for
>> -            # (greater than for the 'next' object; less than for
>> -            # the 'previous' object).
>> -            push @same, $e
>> -                if $next && $e->id > $id or !$next && $e->id < $id;
>> -        } else {
>> -            # We found an object with a timestamp different than
>> -            # the 'current' object.
>> -            if (!@same) {
>> -                push @same, $e;
>> -                # We should check to see if this new timestamped  
>> object also
>> -                # has entries adjacent to _it_ that have the same  
>> timestamp.
>> -                while (my $e = $iter->()) {
>> -                    push(@same, $e), next if $e->created_on eq  
>> $e_ts;
>> -                    $iter->('finish'), last;
>> -                }
>> -            } else {
>> -                $iter->('finish');
>> -            }
>> -            return $obj->{$label} = $e unless @same;
>> -            last;
>> -        }
>> +    if ($obj->{$label}) {
>> +        my $o = $obj->load($obj->{$label});
>> +        return $o if $o;
>> +        delete $obj->{label}; # FAIL
>>     }
>> -    if (@same) {
>> -        # If we only have 1 element in @same, return that.
>> -        return $obj->{$label} = $same[0] if @same == 1;
>> -        # Sort remaining elements in @same by id.
>> -        @same = sort { $a->id <=> $b->id } @same;
>> -        # Return front of list (smallest id) if selecting 'next'
>> -        # object. Return tail of list (largest id) if selection  
>> 'previous'.
>> -        return $obj->{$label} = $same[$next ? 0 : $#same];
>> -    }
>> -    return;
>> +
>> +    my $o = $obj->nextprev(
>> +        direction => $direction,
>> +        terms     => { blog_id => $obj->blog_id, %$terms },
>> +        by        => 'created_on',
>> +    );
>> +    $o->{label} = $o->id if $o;
>> +    return $o;
>>  }
>>
>>  sub entry {
>>
>> Modified: branches/release-31/lib/MT/Entry.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/Entry.pm 2008-03-13 18:55:13 UTC  
>> (rev 1522)
>> +++ branches/release-31/lib/MT/Entry.pm 2008-03-13 18:55:27 UTC  
>> (rev 1523)
>> @@ -21,7 +21,7 @@
>>  use MT::Util qw( archive_file_for discover_tb start_end_period  
>> extract_domain
>>                  extract_domains );
>>
>> -use constant CATEGORY_CACHE_TIME => 7 * 24 * 60 * 60;  ## 1 week
>> +sub CATEGORY_CACHE_TIME () { 604800 } ## 7 * 24 * 60 * 60 == 1 week
>>
>>  __PACKAGE__->install_properties({
>>     column_defs => {
>> @@ -56,9 +56,15 @@
>>         authored_on => 1,
>>         week_number => 1,
>>         basename => 1,
>> +        class_authored => {
>> +            columns => [ 'class', 'authored_on' ],
>> +        },
>>         blog_authored => {
>> -            columns => ['blog_id', 'authored_on'],
>> +            columns => [ 'blog_id', 'authored_on' ],
>>         },
>> +        blog_class => {
>> +            columns => [ 'blog_id', 'class', 'status',  
>> 'authored_on' ],
>> +        },
>>     },
>>     child_of => 'MT::Blog',
>>     child_classes =>  
>> ['MT::Comment','MT::Placement','MT::Trackback','MT::FileInfo'],
>> @@ -69,10 +75,10 @@
>>     class_type => 'entry',
>>  });
>>
>> -use constant HOLD    => 1;
>> -use constant RELEASE => 2;
>> -use constant REVIEW  => 3;
>> -use constant FUTURE  => 4;
>> +sub HOLD ()    { 1 }
>> +sub RELEASE () { 2 }
>> +sub REVIEW ()  { 3 }
>> +sub FUTURE ()  { 4 }
>>
>>  use Exporter;
>>  *import = \&Exporter::import;
>> @@ -175,7 +181,7 @@
>>     $label .= ':category='. $terms->{category_id} if exists $terms- 
>> >{category_id};
>>     if ($obj->{$label}) {
>>         my $o = $obj->load($obj->{$label});
>> -        return if $o;
>> +        return $o if $o;
>>         delete $obj->{label}; # FAIL
>>     }
>>
>>
>> Modified: branches/release-31/lib/MT/ObjectAsset.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/ObjectAsset.pm   2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/ObjectAsset.pm   2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -27,6 +27,7 @@
>>     child_of => 'MT::Blog',
>>     datasource => 'objectasset',
>>     primary_key => 'id',
>> +    cacheable => 0,
>>  });
>>
>>  sub class_label {
>>
>> Modified: branches/release-31/lib/MT/ObjectTag.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/ObjectTag.pm     2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/ObjectTag.pm     2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -28,6 +28,7 @@
>>     child_of => 'MT::Blog',
>>     datasource => 'objecttag',
>>     primary_key => 'id',
>> +    cacheable => 0,
>>  });
>>
>>  sub class_label {
>>
>> Modified: branches/release-31/lib/MT/Placement.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/Placement.pm     2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/Placement.pm     2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -5,10 +5,11 @@
>>  # $Id$
>>
>>  package MT::Placement;
>> +
>>  use strict;
>>
>> -use MT::Object;
>> - at MT::Placement::ISA = qw( MT::Object );
>> +use base qw( MT::Object );
>> +
>>  __PACKAGE__->install_properties({
>>     column_defs => {
>>         'id' => 'integer not null auto_increment',
>> @@ -22,9 +23,13 @@
>>         entry_id => 1,
>>         category_id => 1,
>>         is_primary => 1,
>> +        blog_cat => {
>> +            columns => [ 'blog_id', 'category_id' ],
>> +        },
>>     },
>>     datasource => 'placement',
>>     primary_key => 'id',
>> +    cacheable => 0,
>>  });
>>
>>  sub class_label {
>>
>> Modified: branches/release-31/lib/MT/TBPing.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/TBPing.pm        2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/TBPing.pm        2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -30,7 +30,12 @@
>>     },
>>     indexes => {
>>         created_on => 1,
>> -        blog_id => 1,
>> +        blog_stat => {
>> +            columns => ['blog_id', 'junk_status', 'created_on'],
>> +        },
>> +        blog_visible => {
>> +            columns => ['blog_id', 'visible', 'created_on'],
>> +        },
>>         tb_id => 1,
>>         ip => 1,
>>         visible => 1,
>>
>> Modified: branches/release-31/lib/MT/TemplateMap.pm
>> ===================================================================
>> --- branches/release-31/lib/MT/TemplateMap.pm   2008-03-13 18:55:13  
>> UTC (rev 1522)
>> +++ branches/release-31/lib/MT/TemplateMap.pm   2008-03-13 18:55:27  
>> UTC (rev 1523)
>> @@ -32,6 +32,7 @@
>>     child_classes => ['MT::FileInfo'],
>>     datasource => 'templatemap',
>>     primary_key => 'id',
>> +    cacheable => 0,
>>  });
>>
>>  sub class_label {
>>
>>
>> _______________________________________________
>> MTOS-commits mailing list
>> MTOS-commits at sixapart.com
>> http://www.sixapart.com/mailman/listinfo/mtos-commits
>>
>
>
> -- 
> Timothy Appnel
> Appnel Solutions
> http://appnel.com/
> _______________________________________________
> MTOS-dev mailing list
> MTOS-dev at sixapart.com
> http://www.sixapart.com/mailman/listinfo/mtos-dev

--
Brad Choate
Engineering Manager, Movable Type, Six Apart, Ltd.
http://www.sixapart.com/movabletype/
Mobile: (918) 271-0105  -  AIM: bschoate





More information about the MTOS-dev mailing list