Add revision ID to "jsonapi_normalizations" cache keys

Created on 8 June 2020, over 4 years ago
Updated 15 November 2024, about 1 month ago

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. The existing value at links.via.href may include the resourceVersion GET query parameter if a revision ID is known (entity is revisionable and has a revision).

Example:

{
  "links": {
    "via": {
      "href": "https://example.com/node/12?resourceVersion=id%3A12",
      "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.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component

jsonapi.module

Created by

πŸ‡ΊπŸ‡¦Ukraine BR0kEN Dnipro

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024