-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Broadcast tracker script config updates #5806
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
base: master
Are you sure you want to change the base?
Conversation
|
require Logger | ||
|
||
@spec broadcast_put(any(), Keyword.t()) :: :ok | ||
@spec broadcast_put(any(), any(), Keyword.t()) :: :ok |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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
Changelog
Documentation
Dark mode