Skip to content

Commit

Permalink
chore: even faster max timestamp query
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Sep 19, 2023
1 parent e09c89f commit ab253d1
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit ab253d1

Please sign in to comment.