Skip to content

Commit 8e89eb7

Browse files
authored
Added time-based filters to the mv_session_data pipe (#25708)
ref https://linear.app/ghost/issue/NY-865/analytics-sources-not-populating-for-tangle-due-to-408-timeouts All of the Tinybird endpoints have date-based filters on them. They also are mostly all based on the mv_session_data pipe, but the date filters aren't passed to the mv_session_data pipe at all. This means that Clickhouse has to run the mv_session_data pipe against all events for a particular site across all time, even if it's only going to return the last 30 days in the finished result. Adding the time filters to the mv_session_data pipe should reduce the amount of data that Clickhouse has to scan when any of the endpoints that use it are called, thus improving the performance of any endpoint that depends on it.
1 parent afbcc15 commit 8e89eb7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ghost/core/core/server/data/tinybird/pipes/mv_session_data.pipe

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ SQL >
1818
argMin(utm_content, timestamp) as utm_content
1919
FROM _mv_hits
2020
WHERE site_uuid = {{ String(site_uuid, 'mock_site_uuid', description="Tenant ID", required=True) }}
21+
{% if defined(date_from) %}
22+
AND timestamp >= toDateTime({{ Date(date_from) }}, {{ String(timezone, 'Etc/UTC', description="Site timezone", required=False) }})
23+
{% end %}
24+
{% if defined(date_to) %}
25+
AND timestamp < toDateTime({{ Date(date_to) }}, {{ String(timezone, 'Etc/UTC', description="Site timezone", required=False) }}) + interval 1 day
26+
{% end %}
2127
GROUP BY site_uuid, session_id
2228

2329

0 commit comments

Comments
 (0)