--- lib/MT/Entry.pm.bak	Mon Sep 26 16:12:46 2005
+++ lib/MT/Entry.pm	Wed Oct  5 11:40:41 2005
@@ -272,7 +272,6 @@
         }, {
             'sort' => 'created_on',
             direction => 'descend',
-            limit => 1,
         });
     }
     $entry->{__comment_latest};
--- lib/MT/ObjectDriver/DBM.pm.bak	Fri Sep 23 02:03:13 2005
+++ lib/MT/ObjectDriver/DBM.pm	Wed Oct  5 12:01:47 2005
@@ -351,6 +351,7 @@
     my $idx;
     my(%ids, @ids);
     my $unlock;
+    $args->{'sort'} = '' if $args->{'sort'} eq 'id';
     if (my $col = $args->{'sort'}) {
         my $idx_file = _db_index($driver, $class, $col);
         ($this_db, $idx, $unlock) =
@@ -549,6 +550,8 @@
     %object_cache = ();
 }
 
+use constant MAX_CACHE_SIZE => 1000;
+
 sub load {
     my $driver = shift;
     $driver->run_callbacks($_[0] . '::pre_load', \@_);
@@ -578,8 +581,14 @@
 	}
 	$driver->run_callbacks($class . '::post_load', \@_, $obj);
         unless (wantarray) {
+            undef $DB;
+            untie %$db;
             $unlock->();
             if ($terms && !(ref $terms)) {
+                if (exists $object_cache{$class} && (scalar keys %{$object_cache{$class}} > MAX_CACHE_SIZE)) {
+                    # garbage collection
+                    $object_cache{$class} = {};
+                }
                 $object_cache{$class}->{$terms} = $obj;
             }
             return($obj);
