r1tsuu/payload-enchants

Cached Local API: related documents are not revalidated

Opened this issue · 1 comments

Hi,

Say I have a jobs and organizations collections, where jobs has a relationship field organization to organizations. Both of the collections are enabled in the cached local API config for revalidation and are revalidating successfully upon change.

However, when I update an organization, the nested field title of organization doesn't update, i.e. jobs.docs[0].organization.title.

const jobs = await cachedPayload.find({
  collection: 'jobs',
  depth: 1,
})

Initial API shows this:

{
  "docs": [
    {
      "id": "6692b9c62095d45df53a4c6a",
      "title": "Published Job 1",
      "organization": {
        "id": "6692ad052095d45df53a4880",
        "title": "Organization 1",
        "slug": "organization-1",
      },
     ...
     }
  ]
  ...
}

After changing:

{
  "docs": [
    {
      "id": "6692b9c62095d45df53a4c6a",
      "title": "Published Job 1",
      "organization": {
        "id": "6692ad052095d45df53a4880",
        "title": "Organization 1 Changed",
        "slug": "organization-1",
      },
     ...
     }
  ]
  ...
}

But on the frontend, the cached response still shows organization.title as "Organization 1".

I thought, okay, I actually should also revalidate the job itself, which I did, and nothing changed.

Enabling useSimpleCacheStrategy: true, in the config fixed this, but as I understand this calls revalidation after any change in the database, and I don't think that'll be very performant when there'll be thousands of documents.

Maybe I'm missing something, or maybe that's a bug. Appreciate any help, thanks!

Hi @hristokoev, will try to fix it here #91 as well with updating Payload