feat(api): include visitId in the website events response - #4428
Open
light-merlin-dark wants to merge 1 commit into
Open
feat(api): include visitId in the website events response#4428light-merlin-dark wants to merge 1 commit into
light-merlin-dark wants to merge 1 commit into
Conversation
`/api/websites/:websiteId/events` returns sessionId but not visitId, so an API consumer can group events by session and never by visit. The column is already on the model (`WebsiteEvent.visitId`, indexed as `[websiteId, visitId, createdAt]`), and the sibling session-activity query already selects it in both backends — this only brings `/events` in line. Without it, reconstructing visits over a date range costs one `/sessions/:sessionId/activity` request per session, because that is the only endpoint exposing visitId. With it, a single paged `/events` read carries enough to group client-side. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@light-merlin-dark is attempting to deploy a commit to the Umami Software Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Greptile SummaryAdds
Confidence Score: 5/5The PR appears safe to merge, with both database branches exposing the new field consistently. The additive projections use the existing
|
| Filename | Overview |
|---|---|
| src/queries/sql/events/getWebsiteEvents.ts | Adds matching visitId projections to the relational and ClickHouse queries without disrupting the existing response shape. |
Reviews (1): Last reviewed commit: "feat(api): include visitId in the websit..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
visit_idto theselectingetWebsiteEvents, in both the relational and ClickHouse branches. Two lines, additive, no behaviour change to existing fields.Why
GET /api/websites/:websiteId/eventsreturnssessionIdbut notvisitId, so an API consumer can group events by session and never by visit.The column is already on the model —
WebsiteEvent.visitId, indexed as[websiteId, visitId, createdAt]— andgetSessionActivityalready selects it in both backends. This only brings/eventsin line with its sibling.The practical consequence is an N+1. Today, reconstructing visits across a date range means one
/sessions/:sessionId/activityrequest per session, because that is the only endpoint exposingvisitId. On a self-hosted 3.0.3 instance, building a 30-day dashboard view of 60 sessions:/eventsread (pageSize=5000)The single read already returns everything else needed —
sessionId,createdAt,urlPath,referrerDomain,eventType.visitIdis the only field missing, and without it a client either drops visit grouping or falls back to the per-session fan-out.Worth noting for context: the per-request cost looks like a fixed application-layer floor rather than query time. The same instance answers the underlying session-activity SQL in 0.203ms (index scan), while the HTTP request takes ~110–140ms, and throughput plateaus around 9 req/s regardless of client concurrency. So fewer requests is the only lever available to a consumer.
Testing
visitIdcorrectly, with events from one session sharing a single visit id across rows.getSessionActivityClickHouse query line-for-line, but I do not have a ClickHouse deployment to execute it against — flagging that honestly rather than implying coverage I don't have.Disclosure
Prepared by Merlin (@light-merlin-dark) together with an AI agent (Claude Opus 5), from a real self-hosted deployment. Happy to adjust naming, split the backends, or add a docs note for the events endpoint if you'd prefer.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.