reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

Fix cache consistency bug while deleting resources #301

Open cesar-tonnoir opened 3 years ago

cesar-tonnoir commented 3 years ago

Context:

Cachememory.removeResource is executed whenever a resource gets deleted.

This method aims to remove the deleted resource from the collections persisted in service cache.

Bug:

Resources that aren't directly related to the deleted resource get removed from the cache as well.

After investigation, we've found out this is caused by the removeResource method that loops over all the available collections, and removes one item every time, whether or not the target resource has been found.

This seems to be caused by the use of the splice method chained with findIndex : findIndex returns -1 when the resource isn't found, and splice removes the last item of the array.

Resolution:

If findIndex returns -1, avoid calling splice

cesar-tonnoir commented 3 years ago

Hey @pablorsk, what do you think of this one?

I'm struggling to test locally as I can't manage to find a way to build the lib and link it to my project. Any tip ?

Cheers, Cesar.

cesar-tonnoir commented 3 years ago

@pablorsk any news ? thanks

veneliniliev commented 2 years ago

@pablorsk please merge this and release update!!!

veneliniliev commented 2 years ago

@cesar-tonnoir did you find a solution?