kurko / ember-sync

MIT License
282 stars 28 forks source link

emberSync.deleteRecord doesn't cleanup queue on success #13

Closed tute closed 10 years ago

tute commented 10 years ago

Following code performs a DELETE HTTP request ad eternum:

this.emberSync.deleteRecord('user', record);
record.emberSync.save();

This is because upon successful (first) DELETE call the queue is not cleaned up, and the operations is retried every 5 seconds.

tute commented 10 years ago

It seems Job#deletion is calling the second callback, reject, which makes no sense to me.

Call comes from Queue#processNextJob, job.perform() is a rejected promise on successful HTTP DELETE.

tute commented 10 years ago

It may be due to an empty body: https://github.com/rails/jquery-ujs/issues/337.

tute commented 10 years ago

Indeed, ajax will trigger the error callback if DELETE returns 200 with empty body. Following rails diff fixed the issue (changes response from 200 to 204 No Content):

   def destroy
     @model.destroy
-    render nothing: true
+    head :no_content
   end
kurko commented 10 years ago

Ember Sync will rely on the adapters. If the adapter rejects, it'll reject as well. — Sent from Mailbox

On Mon, Jul 7, 2014 at 4:12 PM, Tute Costa notifications@github.com wrote:

Indeed, ajax will trigger the error callback if DELETE returns 200 with empty body. Following rails diff fixed the issue:

   def destroy
     @model.destroy
-    render nothing: true
+    head :no_content
   end

Reply to this email directly or view it on GitHub: https://github.com/kurko/ember-sync/issues/13#issuecomment-48226869

tute commented 10 years ago

Thanks for your input. The issues I've been creating and that kind of architecture facts are good to add into the README, I smell a related PR coming.