feat: route collection-scoped activity queries to single bucket (IN-1231) - #4483
Conversation
…231) Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit 211b03e. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Pull request overview
Adds optimized single-bucket routing for pre-resolved collection activity queries while retaining union-based fallback behavior.
Changes:
- Adds collection bucket routing across buckets 0–9.
- Uses direct routing when both
collectionSlugandbucketIdare provided.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
activityRelations_collection_bucket_routing.pipe |
Selects the requested collection bucket datasource. |
activities_filtered.pipe |
Adds bucketId support and collection filtering. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
services/libs/tinybird/pipes/activityRelations_collection_bucket_routing.pipe:17
- An invalid but defined
bucketId(for example10) reaches this fallback and silently reads bucket 0.activities_filteredthen filters bycollectionSlug, so collections assigned to buckets 1–9 return empty results instead of preserving the union behavior or rejecting the input. Use the existing union as the fallback.
{% end %} as selected_bucket
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
services/libs/tinybird/pipes/activities_filtered.pipe:34
- Validate
bucketIdbefore selecting the single-bucket pipe.defined(bucketId)accepts values outside0–9; the routing pipe then falls back to bucket 0, so a malformed parameter can silently return no activities for a collection assigned to another bucket. Only use the optimized route for a valid bucket, and otherwise retain the union path (or reject the request).
{% if defined(collectionSlug) and defined(bucketId) %}
activityRelations_collection_bucket_routing
…ssing (IN-1231) Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
| SELECT activityId as id, timestamp, type, platform, memberId, organizationId, segmentId | ||
| FROM | ||
| {% if defined(collectionSlug) %} activityRelations_collection_bucket_union | ||
| {% if defined(collectionSlug) %} activityRelations_collection_bucket_routing |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
services/libs/tinybird/pipes/activities_filtered.pipe:33
- This removes the documented backward compatibility: every existing collection-scoped caller that sends only
collectionSlugnow selects the routing pipe and is forced to1 = 0, so all downstream metrics return empty results until every caller is updated. This also contradicts the PR description, which sayscollectionSlug-only requests continue using the union and that the change is inert without the companion PR. Keep the union as the fallback and select the routing pipe only when both parameters are defined.
{% if defined(collectionSlug) %} activityRelations_collection_bucket_routing
Summary
activityRelations_collection_bucket_routing.pipe, a single-bucket routing pipe that mirrors the existing 10-way-union pattern but for collection-scoped queries. Routes to the correct pre-resolved bucket (0-9) based on the optionalbucketIdparameter.activities_filtered.pipeto accept optionalbucketIdalongsidecollectionSlug. When both are provided, routes directly to the single-bucket pipe instead of the union, improving query performance for pre-resolved collections. Fully backward compatible — callers passing onlycollectionSlugcontinue to use the existing union pipe.feat/IN-1231) which wires up the caller-side logic to passbucketId. Can merge independently or in any order relative to the insights PR.Pipes already validated and deployed to Tinybird production by
crowd-tinybird-manager:cloud-management-platforms(34.1M rows); correct row counts confirmedcollectionSlug-only callersJIRA
IN-1231 — Route collection-scoped activity queries to single bucket (insights-driven)