Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295277

Add revision ID to "jsonapi_normalizations" cache keys

$
0
0

At the moment JSON:API is not able to normalize a list of revisions of the same entity because of normalizations' cache. If you pass 10 revisions the normalized structure for all of them will be the same since the first result is cached and used because of matching cache tags, which are resource name and entity ID.

I understand that this functionality is not offered by JSON:API out of the box and to achieve this I wrote a custom code that relies on PHP API (the jsonapi.entity_resource service in particular) even despite a warning that developers shouldn't do that.

Nevertheless, the solution to overcome this problem is simple and seems so logical so I don't think it should stay overboard.

Proposed resolution

Include a revision ID to the cache tags.

API changes

Every 403 error object (omission) receives two new members in the links.via.meta node: resourceId and resourceVersion.

Example:

{
  "links": {
    "via": {
      "href": "https://example.com/node/12",
      "meta": {
        "resourceId": "entity_uuid",
        "resourceVersion": "12"
      }
    },
  }
}

The resourceId is always present and is a UUID of omitted entity. The resourceVersion is always present and can be null in the case when entity has no revision (Drupal\Core\Entity\RevisionableInterface::getRevisionId() returns null) or non-revisilable (the entity class does not implement the Drupal\Core\Entity\RevisionableInterface). A result of getRevisionId() otherwise.


Viewing all articles
Browse latest Browse all 295277

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>