Updated Date is not changing when a linked content is updated

Hi there ! :slightly_smiling_face:

(First post here so tell me if it’s a bit messy)

Let’s say I have a model called “Post” that have a Link field to a “Author” model.

If I change the name of an Author and save it’ll change its updated and published dates, but the posts that this author is linked to will not be updated.
So the posts will have their old updated/published dates.

I think the posts should have a new updated date because the data in the page are actually different from before.

For a bit of context, I’m using Nuxt.js and we have a lot of pages so I’m working on incremental builds. I’m stocking the _publishedAt/_updatedAt of each page to see if they changed and if I need to generate it again.
So with this issue I’ll need to check all the _publishedAt/_updatedAt of all the linked contents. And it can’t scale well because if I have linked contents in my linked contents I’ll have to check a level further.

Do you think of a way I can manage that ? Or should I open a feature request (for me it’s more like a bug)?

Thanks anyway

Hello @clement welcome to Community!!

What you are saying is very clear, but to me it’s not a bug the fact that if you change a linked record we should also update the others. If we did that, what should me set as changed in the other record? What about the revision history?

I think you should fetch all the published/updated at timestamps and use the most recent to invalidate the cache. You are fetching all the content anyway, right?

You can open a feature request instead, to ask if we can do this on the API side, like returning the most recent updated/published at timestamp of a set of records, not sure if there’s a standard way to handle this though? Ideas?

Hey @mat_jack1, thanks !

If you change a linked record we should also update the others. If we did that, what should me set as changed in the other record? What about the revision history?

We were thinking that it should only update its “parents” records (records that have a linked content to it).
For us it don’t need to appear in the revision history of the parents page, because its changes are not directly visibles on the parent page.

But from an architectural view, if we fetch the PostRecord and all its fields (including the linked AuthorRecord field) from the GraphQL API, the data will be actually different if we change some of the author’s info. So, I think, that the updatedAt should reflect that and it would tell us that the data we just got are newer.

I think you should fetch all the published/updated at timestamps and use the most recent to invalidate the cache. You are fetching all the content anyway, right?

No, we don’t fetch all the contents of each page record.
We have a lot of pages and when we need to build the site it’s 99% of the time because only one page changed. So to not make long queries for nothing, we only fetch the publishedAt of each page and if it’s newer, then we fetch all its content.

We have a lot of modules (linked model) on each page, so we’ll need to check all the publisheAt of all the linked content of each page ?

This is what we’re doing on the first call:

allLandings {
  _publishedAt
  // ... locale stuff
}

And if I understand correctly, we’ll need to do that ? :

allLandings {
  _publishedAt
  hero {
    ... on LandingHeroFormRecord {
      _publishedAt
      form{
        formLines {
          formLine {
            ...on InputRecord {
              _publishedAt
            }
            ...on InputHiddenRecord {
              _publishedAt
            }
            ...on SelectRecord {
              _publishedAt
            }
            ...on GroupsSelectRecord {
              _publishedAt
              optionsGroups {
                ...on OptionGroupRecord {
                  _publishedAt
                }
              }
            }
            ...on TextareaRecord {
              _publishedAt
            }
           }
        }
      }
    }
    ... on LandingHeroVideoRecord {
      _publishedAt
    }
    ... on LandingHeroImageRecord {
      _publishedAt
    }
    ... on LandingHeroIllustrationRecord {
      _publishedAt
    }
  }
  // ... locale stuff
}

And this is only one module (hero) for only one page type (landing). We have around 10 different page type and each as around 40 different modules. Without even counting the nested linked contents (like in the form field above)

To us it seems to be a lot of things to do to only check if the page data have changed. It’s not scalable either, we would have to change this query every time we add a linked content anywhere in the tree.


Sorry about the amount of text :grimacing:
But, again, this is critical to do incremental builds on DatoCMS. We think, more and more JAMSTACK developers will need incremental builds, that’s why I explained a lot of our process here, if it can help other people.

A _dataChangedAt field in the API might be the best option.
Anyway, maybe we’re doing it all wrong ! :sweat_smile: Do you think of someway else ?

Thanks a lot !

I see your point @clement and it makes a lot of sense.

I don’t think though that conceptually is correct to update the timestamps of a record if a linked one is updated. The field in the “top record” is a link, which does not change, I don’t think that it makes sense to mark the record as updated.

For you, I think there are various alternatives.

  1. to delegate everything to DatoCMS I think you should use the modular contents rather than the links. Have you invesigated that? Would that make sense for you?
  2. handle the caching yourself maybe by hashing the content and checking if it’s different? There are surely more intelligent ways, my point is to manage the caching intelligently somehow on your end;
  3. use webhooks to update a field in the parent where you store your updatedAt field. That would make your logic much simpler on the frontend at the cost of implementing some serverless logic to keep the main updatedAt field updated;
  4. open a feature request and if we see that there is some interest we can think about having an option to allow that behaviour.

My feeling though is that if you need us to handle that you should use the modular contents.

What do you think?

Hi @mat_jack1,

You’re right, it should not be tied to the _updatedAt but a new meta field like maybe _pageChangedAt.

  1. Actually we’re already using modular content, but we can’t have nested modular content that’s why we need an extra link in each modular content item.
  2. Yes I think this what we’ll do, instead of just using the _publishedAt to invalidate the cache we’ll compare all of the data of each page.
  3. Nice, we didn’t think of that ! But in our case, there will be too much webhooks if we want to handle all of our models.
  4. Yes we’ll do that ! In the meantime we’ll be using (2.)

Thank for the support !

touché!

I’m sure you’ve noticed it’s our most requested feature: Nested modular fields :frowning:

We’ll surely work on that at some point!