ngx-jsonapi icon indicating copy to clipboard operation
ngx-jsonapi copied to clipboard

Fix cache consistency bug while deleting resources

Open cesar-tonnoir opened this issue 3 years ago • 4 comments

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 avatar Dec 15 '20 19:12 cesar-tonnoir

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 avatar Dec 15 '20 19:12 cesar-tonnoir

@pablorsk any news ? thanks

cesar-tonnoir avatar Jan 13 '21 09:01 cesar-tonnoir

@pablorsk please merge this and release update!!!

veneliniliev avatar Jan 20 '22 13:01 veneliniliev

@cesar-tonnoir did you find a solution?

veneliniliev avatar Feb 09 '22 16:02 veneliniliev