Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

550 cache busting #9447

Merged
merged 4 commits into from
Sep 19, 2024
Merged

550 cache busting #9447

merged 4 commits into from
Sep 19, 2024

Conversation

Harriethw
Copy link
Contributor

@Harriethw Harriethw commented Sep 18, 2024

When a content block is updated we do not want to wait the default cache time of 5 mins in order to see the changes in Documents that use this content block.

Publish intents allow us to reset the cache time for a Document
https://docs.publishing.service.gov.uk/repos/content-store/publish_intents.html

This PR creates a publish intent for any host Documents whenever a block is published.
I've put it at the point of publishing, rather than scheduling or updating, because we can instantly override the cache (or almost instantly depending on length of Sidekiq queue) whereas if we were to call it at point of scheduling, or only when we are updating, it gets a bit trickier to ensure that the method definitely gets called (we would also then have to cancel the intent if a scheduled Block was cancelled)

questions

I've put the PUT requests onto a Worker to be performed asynchronously as Whitehall do. I haven't stress tested this and would need help to do so if we wanted to do so- I'm not sure how slow it would be if a Block had 100-1000s of host Documents, but if it was slower then 5 mins the cache would be refreshed anyway.

To see locally

  1. follow instructions to be able to see published changes locally https://github.com/alphagov/govuk-docker/blob/ddd2f32114416dd543892436df1c144e2bb44b03/docs/how-tos/publishing-content-on-whitehall.md
  2. Create a published Content Block in Whitehall. Get the embed code from the details view e.g. {{embed:content_block_email_address:8603b86f-281d-43ba-b047-9de6d471db05}}
  3. embed that code into a Document (.e.g News Article) and force publish it.
  4. Create log/breakpoint in the content-store repo to see the cache time set for a content item
  5. Go to your published Document on the govuk-frontend, e.g. http://government-frontend.dev.gov.uk/government/news/w-cache and observe the log in content-store should be 300
  6. Update/edit the original published Content Block and publish changes
  7. Observe in Publishing API logs that a PUT request has been made to publish-intent
  8. Visit the published Document in the frontend and observe cache log should now be the difference between the time you re-published the Content Block and now... after 5 minutes the publishing intent will be ignored and cache time set back to 300.

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

@Harriethw Harriethw force-pushed the 550-cache-busting branch 4 times, most recently from e13cf95 to fe78e48 Compare September 18, 2024 17:06
@@ -7,7 +7,7 @@
gds_organisation_id = "af07d5a5-df63-4ddc-9383-6a666845ebe9"
User.create!(
name: "Test user",
permissions: ["signin", "GDS Admin", "GDS Editor", "Managing Editor", "Export data"],
permissions: ["signin", "GDS Admin", "GDS Editor", "Managing Editor", "Export data", "Sidekiq Admin"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just add this for the Test User for good? I feel like it will continue to be useful as we continue to use Sidekiq...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can't see the harm 👍

@Harriethw Harriethw marked this pull request as ready for review September 19, 2024 08:58
@@ -51,6 +52,15 @@ def update_content_block_document(new_content_block_edition:, update_document_pa

private

def remove_cache_for_dependent_content(content_block_edition:)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just realised I'm switching between dependent and host content... i've seen both used elsewhere, shall we stick with Host in the code as that's what we've got already?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's stick with one or the other. I prefer dependent, but as host is used in a lot of places, let's use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, have changed to use host

Copy link
Contributor

@pezholio pezholio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - just one thing about the tests

@@ -51,6 +52,15 @@ def update_content_block_document(new_content_block_edition:, update_document_pa

private

def remove_cache_for_dependent_content(content_block_edition:)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think let's stick with one or the other. I prefer dependent, but as host is used in a lot of places, let's use that.

timestamp = Time.zone.now.to_s
publish_intent = { foo: "bar" }

PublishingApi::PublishIntentPresenter.expects(:new).once.returns(publish_intent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check the arguments the presenter receives too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot, have done

We will shortly use this to add publishing intents
for Documents that have embedded content in them,
when the embedded content is updated and we do not
want to wait the default 5 mins for the cache to
update.
When a content block is updated we do not want to
wait the default cache time of 5 mins in order to
see the changes in Documents that use this content
block.

Publish intents allow us to reset the cache time
https://docs.publishing.service.gov.uk/repos/content-store/publish_intents.html
@Harriethw Harriethw merged commit 084c94b into main Sep 19, 2024
19 checks passed
@Harriethw Harriethw deleted the 550-cache-busting branch September 19, 2024 13:58
Harriethw added a commit to alphagov/publishing-api that referenced this pull request Sep 20, 2024
This returns the publishing app name for all host
editions (Editions with Embedded content in them)

In this previous Whitehal PR [1] we send publish
intents for host Documents of embedded content,
but we hardcoded the publishing app to Whitehall -
we need to see the correct publishing app for all
host editions in order to send these intents.

[1] alphagov/whitehall#9447
Harriethw added a commit to alphagov/publishing-api that referenced this pull request Sep 20, 2024
This returns the publishing app name for all host
editions (Editions with Embedded content in them)

In this previous Whitehal PR [1] we send publish
intents for host Documents of embedded content,
but we hardcoded the publishing app to Whitehall -
we need to see the correct publishing app for all
host editions in order to send these intents.

[1] alphagov/whitehall#9447
Harriethw added a commit that referenced this pull request Sep 20, 2024
we want to send Publish Intents for Host Content (e.g. Editions that
are using embedded content/Content Blocks) [1] that is published
by other apps - this allows an optional app to be passed in, but retains
the default Whitehall value in order not to break existing functionality.

[1] #9447
Harriethw added a commit that referenced this pull request Sep 20, 2024
we want to send Publish Intents for Host Content (e.g. Editions that
are using embedded content/Content Blocks) [1] that is published
by other apps - this allows an optional app to be passed in, but retains
the default Whitehall value in order not to break existing functionality.

[1] #9447
Harriethw added a commit that referenced this pull request Sep 20, 2024
we want to send Publish Intents for Host Content (e.g. Editions that
are using embedded content/Content Blocks) [1] that is published
by other apps - this allows an optional app to be passed in, but retains
the default Whitehall value in order not to break existing functionality.

[1] #9447
Harriethw added a commit that referenced this pull request Sep 24, 2024
we want to send Publish Intents for Host Content (e.g. Editions that
are using embedded content/Content Blocks) [1] that is published
by other apps - this allows an optional app to be passed in, but retains
the default Whitehall value in order not to break existing functionality.

[1] #9447
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants