[CDBI] Do cascading deletes faster

Matt S Trout dbix-class at trout.me.uk
Sun Feb 5 22:48:57 GMT 2006


On Sat, Feb 04, 2006 at 07:11:51PM -0800, Ask Bjørn Hansen wrote:
> Hi,
> 
> Two tables:  "servers" and "log_scores".  Sometimes there are tens of  
> thousands of log_scores per server.  When I delete a server I'd like  
> to make it go faster, so I naively added a before_delete trigger like
> 
> __PACKAGE__->add_trigger(before_delete =>
>                          sub { NTPPool::Server::LogScore- 
> >delete_server($_[0])  }
>                          );
> 
> (delete_server then does a simple $dbh->do to delete all the servers  
> without loading them etc).
> 
> This would be okay for me because there isn't anything cascading from  
> the LogScore class (and no triggers or some such).
> 
> It doesn't work though.  I didn't look closely, but it seems like  
> Class::DBI still does the cascading deletes (or at least the select)  
> first.

That's because Class::DBI uses triggers to implement cascade delete, and
you're calling add_trigger after has_many. Try putting the add_trigger first;
that way your trigger should be the first one to run.

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +




More information about the ClassDBI mailing list