has_moderated icon indicating copy to clipboard operation
has_moderated copied to clipboard

#preview takes >6000 sql requests and >10 minutes

Open nir0 opened this issue 12 years ago • 5 comments

after a while preview started to work in a very strange way (possibly, because we didn't freeze the version)

here's console output https://gist.github.com/4327657

and here's schema, if needed https://gist.github.com/4327661

nir0 avatar Dec 18 '12 16:12 nir0

can you try to debug this more and figure out what is causing it? play with the parameters a bit or something I have no idea what's wrong, it could be some hooks (after_save etc) you might have in your models that are doing something that causes this

mrbrdo avatar Dec 18 '12 16:12 mrbrdo

i tried to debug, and came up with using live_preview instead of preview. somehow preview tried to resolve all methods and relations before rollback. i think, this issue can be closed now, thanks. one last question - what's stable version now, so i can freeze it in gemfile?

nir0 avatar Dec 18 '12 17:12 nir0

The last version is stable. Yes preview tries to resolve all relations, because it converts them to arrays. I will leave it open, I might look into it more one time, but glad live_preview works for you.

mrbrdo avatar Dec 18 '12 18:12 mrbrdo

Happened for me too with preview and not with live_preview. It seems it goes into a loop between the two sides of a has_many through, as it fires lots of single queries for single selects.

Let's say you have A n--------1 X 1--------n B where the X is the join table. It looks like this is happening with preview for an object a of class A:

  • find all related objects of class B;
  • for each of these, find every object of class A that is related to it.

Don't know why this happens, it seems a kind of logic loop to me.

aledalgrande avatar May 12 '13 11:05 aledalgrande

Yeah it must be a bug in the preview stuff. Here is the meat of it: https://github.com/mrbrdo/has_moderated/blob/master/lib/has_moderated/moderation_preview.rb#L42 Probably somewhere here is the problem: https://github.com/mrbrdo/has_moderated/blob/master/lib/has_moderated/moderation_preview.rb#L67 It does seem like it will load in all associations (records themselves)?

I will look at it also, but it might take some time as I am really busy these days.

mrbrdo avatar May 12 '13 14:05 mrbrdo