Skip to content

bugfix: allow cache to merge resource #558

Matthieu Fesselier requested to merge bugfix/558-cache-merge-data into master

This MR introduce one change to the store: when we cache a resource, if it already exists, we merge existing data with the new one.

To test, 2 scenarios:

Scenario 1

  • We load user-1 in the 1rst sib-display which has a city (city-1), with a name.
  • We also load city-1 in the 3rd sib-display which only has a name. The 3rd sib-display should show a name, that's all we know about city-1
  • We click on Set source "user-2". It loads a user-2 in the 2nd sib-display which also has city-1. But this time, it has a zipcode.
  • We click Refresh. The zipcode appears in the3rd sib-display. Datas from city-1 contained in user-2 graph has been merged.
<sib-display
  data-src="user-1.jsonld"
  fields="name"
></sib-display>

<sib-display
  id="user2"
  fields="name"
></sib-display>
<button id="first">Set source "user-2"</button>

<sib-display
  id="city"
  data-src="city-1.jsonld"
  fields="name, zipcode"
></sib-display>
<button id="second">Refresh</button>

<script>
  first.onclick = () => document.getElementById('user2').dataset.src = "user-2.jsonld";
  second.onclick = () => document.getElementById('city').dataset.src = document.getElementById('city').dataset.src;
</script>

with the following datas in jsonld files:

{
  "@id": "user-1.jsonld",
  "name": "John",
  "city": {
    "@id": "city-1.jsonld",
    "name": "Rennes"
  },
  "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
{
  "@id": "user-2.jsonld",
  "name": "Jack",
  "city": {
    "@id": "city-1.jsonld",
    "zipcode": "35000"
  },
  "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
{
  "@id": "city-1.jsonld",
  "name": "Rennes",
  "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}

Scenario 2

  • we load users/matthieu/circles in the 1rst sib-display, which has many circle-members/X, all with a circle property
  • click on Set source circle-members. It loads circle-members/118 in the 3rd sib-display from the cache (it has been cached by the 1rst request). The circle property appears
  • click on Set source members. It loads in the 2nd sib-display: circles/13/members, which has many circle-members/X with user property. It will cache or merge all these circle-members/X/
  • click on refresh. The 3rd sib-display should now also show the user property which has been loaded by the 2nd sib-display

(depending on your account, you may change the src values)

<sib-display
  id="circles"
  data-src="https://api.alpha.happy-dev.fr/users/matthieu/circles/"
  fields="@id"
></sib-display>

<sib-display
  id="members"
  fields="@id"
></sib-display>

<sib-display
  id="circle-members"
  fields="circle, user"
></sib-display>

<button id="first">Set source circle-members</button>
<button id="second">Set source members</button>
<button id="third">Refresh</button>

<script>
  first.onclick = () => document.getElementById('circle-members').dataset.src = "https://api.alpha.happy-dev.fr/circle-members/118/";
  second.onclick = () => document.getElementById('members').dataset.src = "https://api.alpha.happy-dev.fr/circles/13/members/";
  third.onclick = () => document.getElementById('circle-members').dataset.src = document.getElementById('circle-members').dataset.src;
</script>
Edited by Matthieu Fesselier

Merge request reports