Download lib/plausible/site/tracker_script_cache.ex from Leon4gr45/analytics: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/Leon4gr45/analytics/resolve/main/lib/plausible/site/tracker_script_cache.ex
- Command line
-
hf download hf://spaces/Leon4gr45/analytics/lib/plausible/site/tracker_script_cache.ex
-
curl -L -o tracker_script_cache.ex https://huggingface.co/spaces/Leon4gr45/analytics/resolve/main/lib/plausible/site/tracker_script_cache.ex
1.42 kB
| defmodule Plausible.Site.TrackerScriptCache do | |
| @moduledoc """ | |
| Caches the full tracker script. | |
| Must be refreshed whenever the TrackerScriptConfiguration associated with the script changes. | |
| """ | |
| alias Plausible.Site.TrackerScriptConfiguration | |
| alias PlausibleWeb.Tracker | |
| import Ecto.Query | |
| use Plausible | |
| use Plausible.Cache | |
| @cache_name :tracker_script_cache | |
| @impl true | |
| def name(), do: @cache_name | |
| @impl true | |
| def child_id(), do: :cache_tracker_script | |
| def cache_content( | |
| %TrackerScriptConfiguration{site: %{domain: _domain}} = tracker_script_configuration | |
| ), | |
| do: Tracker.build_script(tracker_script_configuration) | |
| @impl true | |
| def count_all() do | |
| Plausible.Repo.aggregate(TrackerScriptConfiguration, :count) | |
| end | |
| @impl true | |
| def base_db_query(), do: Tracker.get_tracker_script_configuration_base_query() | |
| @impl true | |
| def get_from_source(id) do | |
| case Tracker.get_tracker_script_configuration_by_id(id) do | |
| %TrackerScriptConfiguration{site: %{domain: _domain}} = tracker_script_configuration -> | |
| cache_content(tracker_script_configuration) | |
| _ -> | |
| nil | |
| end | |
| end | |
| @impl true | |
| def unwrap_cache_keys(items) do | |
| Enum.reduce(items, [], fn | |
| tracker_script_configuration, acc -> | |
| [ | |
| {tracker_script_configuration.id, cache_content(tracker_script_configuration)} | |
| | acc | |
| ] | |
| end) | |
| end | |
| end | |