jwood / tenacity

A database client independent way of managing relationships between models backed by different databases.
MIT License
118 stars 17 forks source link

Small performance improvement when saving document associations #29

Closed danielgranat closed 12 years ago

danielgranat commented 12 years ago

Improve storing an existing ripple object. Instead of checking to see if an object exists, just expect an exception if it does not (Same as bucket.exists? workd)

jwood commented 12 years ago

Merged. Thanks!

danielgranat commented 12 years ago

A pleasure :)

There is another thing i am looking into, which is adding conditions to ActiveRecord based documents. I found a situation in which i have 2 different classes using the same table, but instances of one class are being deleted by those of the other class.

Anyway, i am going to take look at it tomorrow, so if you have any thoughts about adding conditions will probably help.

Daniel.

On Mon, Aug 15, 2011 at 3:12 AM, jwood reply@reply.github.com wrote:

Merged.  Thanks!

Reply to this email directly or view it on GitHub: https://github.com/jwood/tenacity/pull/29#issuecomment-1803987

jwood commented 12 years ago

Hi Daniel,

Could you provide an example?

Thanks, John

On Mon, Aug 15, 2011 at 10:03 AM, danielgranat < reply@reply.github.com>wrote:

A pleasure :)

There is another thing i am looking into, which is adding conditions to ActiveRecord based documents. I found a situation in which i have 2 different classes using the same table, but instances of one class are being deleted by those of the other class.

Anyway, i am going to take look at it tomorrow, so if you have any thoughts about adding conditions will probably help.

Daniel.

On Mon, Aug 15, 2011 at 3:12 AM, jwood reply@reply.github.com wrote:

Merged. Thanks!

Reply to this email directly or view it on GitHub: https://github.com/jwood/tenacity/pull/29#issuecomment-1803987

Reply to this email directly or view it on GitHub: https://github.com/jwood/tenacity/pull/29#issuecomment-1807796

http://johnpwood.net

danielgranat commented 12 years ago

class PrintTheme > ActiveRecord::Base include Tenacity t_has_many :print_pages, :conditions => ['print_book_id is ?', nil] has_many :templates, :class_name => 'PrintPage', :conditions => ['print_book_id is ? and layout = ?', nil, false], :dependent => :destroy has_many :layouts, :class_name => 'PrintPage', :conditions => ['print_book_id is ? and layout = ?', nil, true], :dependent => :destroy end

Note: the above design is BAD (on our side). Its the same class on different condition.

When saving the class PrintTheme instance, all the associations from print_pages are cleared and re-created. the problem is that it also deletes all the templates associations and that's not recreated because those are not in the print_pages to begin with.

I noticed the deletion in has_many has_many.rb - _t_save_associates. To fix this (again i know our design is wrong here) i tryed adding the condition so when the associations are fetched it will only get the print_pages.

Hope that explain what i see... i intend to look more in to this tomorrow.

Thanks Daniel.

On Mon, Aug 15, 2011 at 6:10 PM, jwood reply@reply.github.com wrote:

Hi Daniel,

Could you provide an example?

Thanks, John

On Mon, Aug 15, 2011 at 10:03 AM, danielgranat < reply@reply.github.com>wrote:

A pleasure :)

There is another thing i am looking into, which is adding conditions to ActiveRecord based documents. I found a situation in which i have 2 different classes using the same table, but instances of one class are being deleted by those of the other class.

Anyway, i am going to take look at it tomorrow, so if you have any thoughts about adding conditions will probably help.

Daniel.

On Mon, Aug 15, 2011 at 3:12 AM, jwood reply@reply.github.com wrote:

Merged.  Thanks!

Reply to this email directly or view it on GitHub: https://github.com/jwood/tenacity/pull/29#issuecomment-1803987

Reply to this email directly or view it on GitHub: https://github.com/jwood/tenacity/pull/29#issuecomment-1807796

http://johnpwood.net

Reply to this email directly or view it on GitHub: https://github.com/jwood/tenacity/pull/29#issuecomment-1807876