Skip to content

Commit

Permalink
[#360 state:resolved] Applied unified patch which eliminates unnecess…
Browse files Browse the repository at this point in the history
…ary entry saves when no fields are updated (i.e. when clicking save and publish just to re-publish entry) and updates of the mt_trackback table when trackbacks are disabled. See http://bugs.movabletype.org/default.asp?104142 for more details. Changed included test prefix 04-meta-entry-save to 24.
  • Loading branch information
tima authored and jayallen committed Sep 27, 2010
1 parent 6557ca1 commit 8f9ce2a
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/MT/Entry.pm
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ sub save {
}
if (my $dt = $entry->authored_on_obj) {
my ($yr, $w) = $dt->week;
$entry->week_number($yr * 100 + $w);
$entry->week_number($yr * 100 + $w) if $yr * 100 + $w != ($entry->week_number || 0);
}
unless ($entry->SUPER::save(@_)) {
print STDERR "error during save: " . $entry->errstr . "\n";
Expand Down
2 changes: 1 addition & 1 deletion lib/MT/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ sub install_properties {
$class->add_trigger( post_save => \&_translate_audited_fields );
}

$class->add_trigger( pre_save => _get_date_translator(\&_ts2db, 1) );
$class->add_trigger( pre_save => _get_date_translator(\&_ts2db, 0) );
$class->add_trigger( post_load => _get_date_translator(\&_db2ts, 0) );
}

Expand Down
79 changes: 79 additions & 0 deletions t/24-meta-entry-save.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use lib qw( t/lib lib extlib );

use strict;
use warnings;

use MT::Test qw( :memcached :db :data :app );
use Test::More tests => 13;

require MT::Entry;

# it's in cache now
# we should *reload it* and start again
my $o = MT::Entry->load (1);

require MT::Object;
MT::Object->driver->clear_cache;

$o = MT::Entry->load (1);
MT::Entry->install_meta ({ column_defs => { my_meta_hash => 'hash meta' }});

ok(!defined $o->my_meta_hash, "New meta column isn't defined yet");

$o->my_meta_hash ({ something => 'other' });

my @queries;
my $start_query = \&MT::ObjectDriver::Driver::DBI::start_query;
*MT::ObjectDriver::Driver::DBI::start_query = sub {
my $driver = shift;
my ($sql, $bind) = @_;
push(@queries, $sql);
my $params = ref $bind eq 'ARRAY' ? "[@{[map {defined() ? $_ : 'undef'} @$bind]}]"
: ref $bind eq 'HASH' ? "{@{[map {defined() ? $_ : 'undef'} %$bind]}}" : $bind;
s/\r?\n/ /g for $sql, $params;
diag " $sql $params\n";
return $start_query->($driver, @_);
};

diag "define new meta field, update it and do obj->save";
@queries = ();
$o->save;
is(grep(/INSERT INTO mt_entry_meta/, @queries), 1, "mt_entry_meta is inserted once");
is(grep(/UPDATE mt_entry /, @queries), 0, "mt_entry is not updated");

$o = MT::Entry->load (1);
$o->my_meta_hash ({ something => 'more' });

diag "update meta field and do obj->save";
@queries = ();
$o->save;
is(grep(/UPDATE mt_entry_meta/, @queries), 1, "mt_entry_meta is updated once");
is(grep(/UPDATE mt_entry /, @queries), 0, "mt_entry is not updated");

$o->my_meta_hash ({ something => 'else' });

diag "update meta field and do obj->meta_obj->save";
@queries = ();
$o->meta_obj->save;
is(grep(/UPDATE mt_entry_meta/, @queries), 1, "mt_entry_meta is updated once");
is(grep(/UPDATE mt_entry /, @queries), 0, "mt_entry is not updated");

diag "do obj->save";
@queries = ();
$o->save;
is(grep(/UPDATE mt_entry_meta/, @queries), 0, "mt_entry_meta is not updated");
is(grep(/UPDATE mt_entry /, @queries), 0, "mt_entry is not updated");

$o->text_more('foo bar');
diag "update one of direct fields and do obj->save";
@queries = ();
$o->save;
is(grep(/UPDATE mt_entry_meta/, @queries), 0, "mt_entry_meta is not updated");
is(grep(/UPDATE mt_entry /, @queries), 1, "mt_entry is updated once");

diag "do obj->save";
@queries = ();
$o->save;
is(grep(/UPDATE mt_entry_meta/, @queries), 0, "mt_entry_meta is not updated");
is(grep(/UPDATE mt_entry /, @queries), 0, "mt_entry is not updated");

0 comments on commit 8f9ce2a

Please sign in to comment.