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

chore: even faster max timestamp query #17533

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion posthog/clickhouse/system_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ def system_status() -> Generator[SystemStatusRow, None, None]:
# This timestamp is a naive timestamp (does not include a timezone)
# ClickHouse always stores timezone agnostic unix timestamp
# See https://clickhouse.com/docs/en/sql-reference/data-types/datetime#usage-remarks
last_event_ingested_timestamp = sync_execute("SELECT max(_timestamp) FROM events")[0][0]
last_event_ingested_timestamp = sync_execute(
"""
SELECT max(_timestamp) FROM events
WHERE timestamp >= now() - INTERVAL 1 HOUR
"""
)[0][0]

# Therefore we can confidently apply the UTC timezone
last_event_ingested_timestamp_utc = last_event_ingested_timestamp.replace(tzinfo=ZoneInfo("UTC"))
Expand Down
Loading