The store does not handle concurrent calls well
Expected behavior
When a call is made to a resource while all its children have not been cached completely, the store returns null values
What's happening?
Here is a timeline of what's happening:
-
component1 loads
matthieu/circles/
- caching
matthieu/circles
- caching
circle-members/1
- caching
circle-members/2
- ...
- caching
-
component2 asks for
matthieu/circles
-> already in the cache, container returned- iterate on resources of the container
- get
circle-members/1
-> returned from the cache - get
circle-members/2
-> returned from the cache - get
circle-members/3
-> not in the cache, returnnull
-
component1 still loading
- caching
circle-members/3
- resolve and return
- caching
Steps to reproduce
In a page with core@0.10, execute this script:
document.addEventListener('DOMContentLoaded', async() => {
const context = {
'@vocab': 'http://happy-dev.fr/owl/#',
ldp: 'http://www.w3.org/ns/ldp#',
};
store.getData("https://api.test1.startinblox.com/users/", context).then(() => {
const userProfile = store.get('https://api.test1.startinblox.com/users/jbpasquier/')
return userProfile['circles'];
}).then(() => {
console.log(store.cache.get('https://api.test2.startinblox.com/circle-members/22/'))
});
setTimeout(() => {
console.log(store.get('https://api.test1.startinblox.com/users/jbpasquier/circles/')['ldp:contains'])
}, 500);
})
You will see the second log appear first. An array with 2 proxies and 1 null will be displayed, because the 3rd resource is distant and not included in the container. When the log happens, the request to fetch it is still loading. You may have to adjust the timeout to see it.