|
| 1 | +DESCRIPTION > |
| 2 | + - `collection_contributors_leaderboard.pipe` serves the contributors leaderboard widget for a |
| 3 | + collection's Contributors tab, aggregated across every project in the collection. |
| 4 | + - Separate from `contributors_leaderboard.pipe` (the single-project version) because a naive |
| 5 | + collection-scoped port of that pipe's `ROUND(COUNT(af.id) * 100.0 / SUM(COUNT(af.id)) OVER (), 2)` |
| 6 | + contributionPercentage forces ClickHouse to fully materialize the per-member GROUP BY (potentially |
| 7 | + hundreds of thousands of distinct members at collection scale) before it can apply ORDER BY/LIMIT - |
| 8 | + confirmed via direct timing: the equivalent single-project pipe took 7-16s (once timing out |
| 9 | + entirely at Tinybird's 20s limit) on a 242-project collection, vs 2-3s for the count-only path |
| 10 | + with no window function. This pipe computes the total contribution count as a separate scalar |
| 11 | + subquery instead of a window function, avoiding that full-materialization cost. |
| 12 | + - Supports both count mode (`count=true`) and data mode for pagination-friendly leaderboard display. |
| 13 | + - Always shows `displayName` (not `publicName`) since a collection spans many projects with mixed |
| 14 | + LF/non-LF status - there's no single project-type answer to substitute on, unlike the single-project |
| 15 | + pipe's `is_request_from_non_lf_project` check. |
| 16 | + - Primary use case: powering the collection-scoped contributor ranking widget on Collection detail |
| 17 | + pages' Contributors tab. |
| 18 | + - Parameters: |
| 19 | + - `collectionSlug`: Required collection slug (e.g., 'cncf') - inherited from `segments_filtered_by_collection`. |
| 20 | + - `repos`: Optional array of repository URLs for filtering (inherited from `segments_filtered_by_collection`) |
| 21 | + - `startDate`: Optional DateTime filter for activities after timestamp (e.g., '2024-01-01 00:00:00') |
| 22 | + - `endDate`: Optional DateTime filter for activities before timestamp (e.g., '2024-12-31 23:59:59') |
| 23 | + - `platform`: Optional string filter for source platform (e.g., 'github', 'discord', 'slack') |
| 24 | + - `activity_type`: Optional string filter for single activity type (e.g., 'authored-commit') |
| 25 | + - `activity_types`: Optional array of activity types (e.g., ['authored-commit', 'co-authored-commit']) |
| 26 | + - `includeCollaborations`: Optional boolean, defaults to false - same toggle as the single-project pipe. |
| 27 | + - `count`: Optional boolean, when true returns contributor count instead of leaderboard data |
| 28 | + - `limit`: Optional integer for result pagination, defaults to 10 |
| 29 | + - `offset`: Optional integer for result pagination, defaults to 0 |
| 30 | + - Response: |
| 31 | + - Count mode (`count=true`): `count` (total number of contributors) |
| 32 | + - Data mode (default): `id`, `avatar`, `displayName`, `githubHandleArray`, `contributionCount`, `contributionPercentage`, `roles` |
| 33 | + |
| 34 | +TAGS "Insights, Widget", "Collection", "Contributors" |
| 35 | + |
| 36 | +NODE collection_contributors_total |
| 37 | +DESCRIPTION > |
| 38 | + Total contribution count across the collection - a plain aggregate with no GROUP BY, so it's |
| 39 | + cheap regardless of how many distinct members contributed. Computed once and reused as a scalar |
| 40 | + for the percentage calculation instead of a SUM(...) OVER () window function. |
| 41 | + |
| 42 | +SQL > |
| 43 | + % |
| 44 | + SELECT count(af.id) AS total FROM activities_filtered af |
| 45 | + |
| 46 | +NODE collection_member_aggregates |
| 47 | +DESCRIPTION > |
| 48 | + Per-member contribution counts, ranked and paginated. No window function here - the percentage |
| 49 | + is computed in the next node against the scalar total, so ORDER BY/LIMIT can apply directly |
| 50 | + after this GROUP BY without waiting on a second full-set pass. |
| 51 | + |
| 52 | +SQL > |
| 53 | + % |
| 54 | + {% if Boolean(count, false) %} SELECT count(distinct af.memberId) FROM activities_filtered af |
| 55 | + {% else %} |
| 56 | + SELECT af.memberId, count(af.id) AS contributionCount |
| 57 | + FROM activities_filtered af |
| 58 | + GROUP BY af.memberId |
| 59 | + ORDER BY contributionCount DESC, af.memberId DESC |
| 60 | + LIMIT {{ Int32(limit, 10) }} |
| 61 | + OFFSET {{ Int32(offset, 0) }} |
| 62 | + {% end %} |
| 63 | + |
| 64 | +NODE collection_contributors_leaderboard_result |
| 65 | +SQL > |
| 66 | + % |
| 67 | + {% if Boolean(count, false) %} |
| 68 | + SELECT count(distinct af.memberId) AS count FROM activities_filtered af |
| 69 | + {% else %} |
| 70 | + SELECT |
| 71 | + m.id, |
| 72 | + m.avatar, |
| 73 | + m.displayName, |
| 74 | + m.githubHandleArray, |
| 75 | + ma.contributionCount, |
| 76 | + ROUND(ma.contributionCount * 100.0 / total.total, 2) AS contributionPercentage, |
| 77 | + mr.roles |
| 78 | + FROM members_sorted AS m any |
| 79 | + INNER JOIN collection_member_aggregates ma ON ma.memberId = m.id |
| 80 | + LEFT JOIN member_roles mr ON mr.memberId = m.id |
| 81 | + CROSS JOIN collection_contributors_total total |
| 82 | + WHERE m.id IN (SELECT memberId FROM collection_member_aggregates) |
| 83 | + ORDER BY contributionCount DESC |
| 84 | + {% end %} |
0 commit comments