Ruby on Rails Friday, November 26, 2010

On Nov 26, 8:33 pm, Uday Shankar <li...@ruby-forum.com> wrote:
> Hi,
>
> I am fairly new to rails and ajax as well. I have hinch that the problem
> i am facing is related to ajax requests. During the first ajax call,
> adding a new entry to the data is requested but before this request is
> complete another ajax call is made to the access the same dataset to
> view one of the data content. I feel somewhere these two ajax calls gets
> interleaved and the backend data is not updated to make the new entry
> that was requested first. Please suggest a way to investigate how to
> trace the ajax calls and if there is any possibility of this hunch might
> be true.

It's entirely possible that overlapping ajax calls could trigger a
race condition. For example if your controller does

foo = Foo.find(params[:id])
# change some attributes
foo.save!

And you have 2 requests that come in at close to the same time then
the sequencing can look like

1: instance one does Foo.find
2: instance two does Foo.find
3: instance one updates and saves
4: instance two updates and saves, overwriting the changes made in 3.
if you have a feeling that this might be the case, one thing that I
sometimes find helpful is to insert a few sleeps into the app at
strategic points so as to make the race condition more likely.
Depending on what sort of stuff you are doing to your models, you may
find optimistic locking useful


Fred
>
> Thanks,
> Uday.
>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment