Skip to content

Conversation

apata
Copy link
Contributor

@apata apata commented Oct 14, 2025

Changes

Broadcasts tracker script config creates / updates to other app nodes, reducing the time between creating / updating a script and being able to reliably receive it.

Tests

  • Automated tests have been added
  • This PR does not require tests

Changelog

  • Entry has been added to changelog
  • This PR does not make a user-facing change

Documentation

  • Docs have been updated
  • This change does not need a documentation update

Dark mode

  • The UI has been tested both in dark and light mode
  • This PR does not change the UI

@apata apata added the preview label Oct 14, 2025
Copy link

Preview environment👷🏼‍♀️🏗️
PR-5806

require Logger

@spec broadcast_put(any(), Keyword.t()) :: :ok
@spec broadcast_put(any(), any(), Keyword.t()) :: :ok
Copy link
Member

Choose a reason for hiding this comment

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

👍


def broadcast_script_update(tracker_script_configuration),
do:
PlausibleWeb.TrackerScriptCache.broadcast_put(
Copy link
Member

Choose a reason for hiding this comment

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

minor, just noticed this - by convention, *Web namespace if for HTTP things. Cache is completely agnostic in that sense, even if Web things are its clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I hadn't considered the namespace question. At the moment we have the script at Plausible.Site.TrackerScriptConfiguration. By following existing naming principles, its Cache should be at Plausible.Site.TrackerScriptConfiguration.Cache, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah damn, it's not so straightforward. It caches the script, not the configuration. The script's module is PlausibleWeb.Tracker. So PlausibleWeb.Tracker.Cache or refactor also PlausibleWeb.Tracker to Plausible.Tracker?

Copy link
Member

Choose a reason for hiding this comment

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

refactor also PlausibleWeb.Tracker to Plausible.Tracker

Probably this, but we can live with not doing it

end

defp cache_content(tracker_script_configuration) do
def cache_content(tracker_script_configuration) do
Copy link
Member

Choose a reason for hiding this comment

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

a bit unclear what is this function for. returns either always true or some string for CE? And build_script for CE does eex-like string replace but not using EEx? Very confusing. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Agreed that this could use a comment. Will put something like the following:

On EE, we cache that this particular script exists to prevent Postgres stress from lookups of non-existent script IDs. The heavy lifting of caching is left to the CDN. If the ID exists, we always generate a fresh version of the script.

On CE, since we don't anticipate them using a CDN, we cache the rendered script.

Regarding the CE solution, it means that every refresh interval, every script is re-rendered by the server. This doesn't seem ideal actually.

Regarding building the script, we planned to use EEx but there were issues. There's a discussion on the PR that introduced it.

Copy link
Contributor Author

@apata apata Oct 16, 2025

Choose a reason for hiding this comment

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

Regarding the CE solution, it means that every refresh interval, every script is re-rendered by the server. This doesn't seem ideal actually.

Just realised that only every updated script is re-rendered by the server on CE. That's not a problem.

Copy link
Member

@aerosol aerosol left a comment

Choose a reason for hiding this comment

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

The CI error looks related to the change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants