Repository navigation
Find all references to a story in published content #587
Unanswered
hpohlmeyer
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Intro
I am looking for a way to find all deeply nested references that target a specific story in "published" state. This is needed if we want to control cache invalidation via webhooks and seems to be something that is not possible right now.
I've already talked to the storyblok support, but we did not find a solution. That's why I've decided to write it up here to have
a write-up that I can reference and see if anyone has an idea on how to solve it without tracking the reference graph on our own
servers.
Setup
The only way to invalidate our cache is to manually invalidate it via webhooks. From our tests, there is no way to properly invalidate stories which have a reference to another story.
Let's assume this is our scenario:
We have two blocks with the following field config:
From that, we create two new stories. To make it easier to read, I've replaced the uuids with single letters.
{ "uuid": "A", "full_slug": "a", "content": { "component": "Todo" } }{ "uuid": "B", "full_slug": "b", "content": { "component": "TodoList", "todos": [ { "uuid": "C", "component": "Todo", "content": { "reference": "A" } } ] } }Now we publish both stories. Afterwards we remove the reference to
Ainside storyBand save the story, but do not publish it. That leaves us with a reference between the stories in the published version ofB, but not in thedraftversion.After both
publishedstories have been cached by our app, my webhook receives an action for storyA. Here is an example payload:{ "action": "published", "space_id": "12345", "story_id": "54321", "full_slug": "a", }Figuring out the referrer stories
Now I need to invalidate the cache for both
AandB, because the both use storyA.Invalidating
Ais easy. The webhook gives me all the info that I need. The invalidation ofBis where I run into problems.Option 1: Management API
I could use the
reference_searchquery parameter to get all the stories that refer toA:I would assume it resolves all references inside a story (no matter the depth) recursively and returns all stories that reference my
Astory. I have not checked if it does, because the problem with this approach is that the management API only allows you to query the current state of the story (draft). This does not help me in this case, because the reference only exists in thepublishedversion.Option 2: Content Delivery API
The only way to query
publishedcontent is the content delivery API. Unfortunately thereference_searchquery parameter does not exist here. But if we look at the published json, thereferencefield uses the referenced stories'uuidas the value.This should make it available to the
search_termparameter as stated in the docs:So I am using this query:
Unfortunately that does only return the
Astory to me. I have tried to resolve relations as well, but none of that helped. But even if that worked, I would still have to ensure that I resolve all relations manually in case I have multiple nested story references.Verdict
I am out of options here. Without a proper way of finding referrer stories, we end up with partially-invalidated caches. The only options to work around that is to revalidate the cache on a timeout or to keep track of the reference graph on our own servers.
All reactions