meteor-collection-softremovable icon indicating copy to clipboard operation
meteor-collection-softremovable copied to clipboard

Restore always returns 0

Open serkandurusoy opened this issue 9 years ago • 12 comments

Restoring a document returns 0 even on successful restore whereas it should be returning 1 just like it does when softremoved.

serkandurusoy avatar Aug 02 '15 20:08 serkandurusoy

I'll look into it as soon as possible

zimme avatar Aug 03 '15 05:08 zimme

Great, thanks!

serkandurusoy avatar Aug 03 '15 06:08 serkandurusoy

So what I think is going on here is that if you publish a set of posts if will only publish the posts which aren't soft-removed.

Then you soft remove 1 post and that post will no longer be published to the client, because it's soft-removed.

Then when you restore that same post using it's _id, the post will get restored but as it's not in the clients local Posts collection. The restore function running in client code won't restore anything and it will return 0 and then the code running on server will restore it and the client won't get the response of the server call.

I'm looking into re-implmenting the softRemove and restore functions more like that way insert/update/remove is implemented.

zimme avatar Aug 23 '15 18:08 zimme

Ah yes that makes sense!

serkandurusoy avatar Aug 23 '15 20:08 serkandurusoy

The reason that this works this way is because I allow softRemove and restore to soft-remove and restore documents from client-side calls, even if they aren't published to the client, by specifying the documents _id.

I'll have a closer look at how remove works and if that works like softRemove does now, I'm not changing anything. However I believe it doesn't which is why I'm thinking I should really change softRemove/restore not to allow soft-remove/restore from client side on document which isn't published to client.

zimme avatar Aug 23 '15 20:08 zimme

I've given this more thought. I think you should not waste time looking into this.

If we are on the client and we don't have the id of a removed item by normal means, we don't need to be able to recover it by normal means either.

If we are on the client and know the id of a softremoved document, that actually means that we've deliberately subscribed to a publication that sends down those documents to the client, so I guess the client can use a server method for this.

But, I do believe that this should be pointed out in the documentation as a caveat.

serkandurusoy avatar Aug 23 '15 21:08 serkandurusoy

I'm just gonna benchmark this against remove and make softRemove and restore work the same way. It might be less convenient BUT I feel that keeping my API as close to Meteor's is the best way to go with these functions.

There's a small change I've already benchmarked this against remove and that's why my functions work the way they do today :stuck_out_tongue:

But as you said, I need to update documentation either way.

zimme avatar Aug 23 '15 21:08 zimme

:+1:

serkandurusoy avatar Aug 23 '15 21:08 serkandurusoy

I've tried to get this fixed, but I'm pretty sure I'll need to do some fundamental changes which are breaking changes in the behaviour of remove and restore and that'll need a major version bump.

I'll try and get this done the coming weekend, hackathon time ;)

zimme avatar Oct 05 '15 10:10 zimme

Let me know if there's anything I can do to help :)

serkandurusoy avatar Oct 05 '15 11:10 serkandurusoy

After the changes I plan, you won't be able to restore or softRemove document from client unless the documents have been published to the client.

This should sort out the restore returning 0 even if the restore was successful thing, but it'll be breaking changes, as people might be using the restore by id passthrough behaviour that's in play now.

I just need to benchmark against remove first too.

zimme avatar Oct 05 '15 11:10 zimme

Well, I'd like to repeat this

If we are on the client and know the id of a softremoved document, that actually means that we've deliberately subscribed to a publication that sends down those documents to the client, so I guess the client can use a server method for this.

You really don't have to cover all the edge cases. Even though I requested this, I now know that my reasoning was based on false pretense.

serkandurusoy avatar Oct 05 '15 12:10 serkandurusoy