ngx-jsonapi
ngx-jsonapi copied to clipboard
Fix cache consistency bug while deleting resources
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
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.
@pablorsk any news ? thanks
@pablorsk please merge this and release update!!!
@cesar-tonnoir did you find a solution?