On 1/11/07, Tobias <[EMAIL PROTECTED]> wrote:
Hi everybody,I'm writing a forum application with DBIx::Class and Catalyst. Every post in a forum is stored using two tables (for performance reasons): * posts - (DBIC class "Forum::Post") contains basic data for every post has_one relationship with Forum::PostText * post_texts - (DBIC class "Forum::PostText") contains just the texts belongs_to Forum::Post I'm wondering what's the best way to encapsulate this because I don't want to make calls to several DBIx::Class classes everywhere I want to insert a new post (i.e. in Catalyst controllers). Should I just create a third class outside the Schema namespace which utilizes all neccessary DBIx::Class classes for inserting a new post to hide the underlying separation into two tables from the rest of the application? What I want is to call _ONE_ method in my Catalyst controllers to insert a new post into the database. The controller shouldn't worry if the data gets stored in one, two or ten tables. Maybe there's some sort of DBIx::Class magic to do this without having to add an extra layer myself?
You might consider whether splitting this table was a premature optimization. I can't know if it is, it's really up to you, but it's often the case (especially with forum posts, as the most typical pattern will be to insert the data once and then read-only from there out, with only a small fraction of the texts being updated by later edits, and even then very few times). Usually the case where this sort of table-splitting is most likely to make a real performance improvement that's worth it is when the data in Forum::Post is being constantly UPDATEd while the related text in Form::PostText remains static and is heavily accessed/searched. Have you benchmarked typical operations you expect your code to do against the single-table version and the double-table version? You're paying a high cost for this optimization (the complexity which leads to you posting this question), you might want to be sure its really worth it. -- Brandon _______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/[email protected]/
