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 Blocks - #24 by mariacheline :frowning:

Weā€™ll surely work on that at some point!