cozy / cozy-client-js

Javascript library to write Cozy applications
https://docs.cozy.io/en/cozy-client-js/README/
MIT License
11 stars 12 forks source link

Add one retry on index definition to avoid stack error #205

Closed CPatchane closed 7 years ago

gregorylegarec commented 7 years ago

Thanks @CPatchane 🍰

y-lohse commented 7 years ago

@CPatchane Can you give some background as to why we need to automatically do a find after the index is created please?

Without context it seems very strange to fire an unexpected request, whose result is discarded. It also breaks here if the _id field wasn't part of the index. Maybe we can find a better way to solve whatever the problem was 😃

CPatchane commented 7 years ago

@y-lohse The problem was that at the first usage, when the index is created and returned to the client, it was actually not already available and cause an error on the client saying that the index doesn't exist. It's the case in production when using cozy-collect for the first time. I wanted to add some retries here to avoid this specific case. But I agree that I didn't test for other kind of index and I thought that all index was answering on _id but I can be wrong.

y-lohse commented 7 years ago

@CPatchane I can't reproduce the problem you're describing though :/. Here's where I'm creating an index and using it right away. It's also surprising to me because we've been using indexes on photos for a while without problem. Are you sure this wasn't an issue specific to cozy-collect? Maybe we could move this code to cozy-collect instead of having it here where it impacts every app using indexes, sometimes negatively when _id isn't part of the index?

CPatchane commented 7 years ago

I know. This issue can happen only on production due to CouchDB usage (which is different from the local development) and only when you create the index for the very first time. It can be difficult to reproduce, but that could happen sometimes when a new user discover its new cozy. We reproduce it (not always) when we created new test intances on staging/production.

y-lohse commented 7 years ago

Ugh, ok. In that case, I suggest we do the following:

Do you think this would work?

CPatchane commented 7 years ago

@y-lohse Completely agree with your points here to improve that parts 👍 That should work for me.

y-lohse commented 7 years ago

Cool, I'll probably submit a PR later today then :)

CPatchane commented 7 years ago

Great @y-lohse Thanks 👍