Skip to content

Commit a03137f

Browse files
committed
feat: support collections sorting by contributor count
Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
1 parent 294ac7c commit a03137f

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

services/libs/tinybird/pipes/collections_list.pipe

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,37 @@ DESCRIPTION >
1616
- Count mode (`count=true`): `count` (total number of collections)
1717
- Data mode (default): `id`, `name`, `slug`, `description`, `projectCount`, `starred`, `softwareValue`, `contributorCount`, `featuredProjects` array
1818

19-
NODE collections_paginated
19+
NODE collections_list_software_value
20+
SQL >
21+
SELECT
22+
collectionId,
23+
coalesce(sum(softwareValue), 0) as "softwareValue",
24+
coalesce(sum(contributorCount), 0) as "contributorCount"
25+
FROM segments_aggregates_with_ids_datasource
26+
WHERE collectionId != ''
27+
GROUP BY collectionId
28+
29+
NODE collections_enriched
2030
SQL >
21-
%
2231
SELECT
2332
collections_filtered.id,
2433
collections_filtered.name,
2534
collections_filtered.slug,
2635
collections_filtered.description,
2736
collections_filtered.projectCount,
28-
collections_filtered.starred
37+
collections_filtered.starred,
38+
coalesce(collections_list_software_value.softwareValue, 0) as softwareValue,
39+
coalesce(collections_list_software_value.contributorCount, 0) as contributorCount
2940
FROM collections_filtered
41+
LEFT JOIN
42+
collections_list_software_value
43+
ON collections_list_software_value.collectionId = collections_filtered.id
44+
45+
NODE collections_paginated
46+
SQL >
47+
%
48+
SELECT id, name, slug, description, projectCount, starred, softwareValue, contributorCount
49+
FROM collections_enriched
3050
order by
3151
{{
3252
column(
@@ -61,16 +81,6 @@ SQL >
6181
(collectionsInsightsProjects.collectionId in (select id from collections_paginated))
6282
and collectionsInsightsProjects.starred
6383

64-
NODE collections_list_software_value
65-
SQL >
66-
SELECT
67-
collectionId,
68-
coalesce(sum(softwareValue), 0) as "softwareValue",
69-
coalesce(sum(contributorCount), 0) as "contributorCount"
70-
FROM segments_aggregates_with_ids_datasource
71-
WHERE collectionId != ''
72-
GROUP BY collectionId
73-
7484
NODE merging_fields_together
7585
SQL >
7686
%
@@ -83,8 +93,8 @@ SQL >
8393
collections_paginated.description as description,
8494
collections_paginated.projectCount as "projectCount",
8595
collections_paginated.starred as starred,
86-
collections_list_software_value.softwareValue as softwareValue,
87-
collections_list_software_value.contributorCount as contributorCount,
96+
collections_paginated.softwareValue as softwareValue,
97+
collections_paginated.contributorCount as contributorCount,
8898
arrayFilter(
8999
x -> x['name'] != '',
90100
groupArray(
@@ -102,18 +112,15 @@ SQL >
102112
LEFT JOIN
103113
collections_featured_projects
104114
ON collections_featured_projects.collectionId = collections_paginated.id
105-
LEFT JOIN
106-
collections_list_software_value
107-
ON collections_list_software_value.collectionId = collections_paginated.id
108115
GROUP BY
109-
collections_paginated.id as id,
110-
collections_paginated.name as name,
111-
collections_paginated.slug as slug,
112-
collections_paginated.description as description,
113-
collections_paginated.projectCount as "projectCount",
114-
collections_paginated.starred as starred,
115-
collections_list_software_value.softwareValue as softwareValue,
116-
collections_list_software_value.contributorCount as contributorCount
116+
collections_paginated.id,
117+
collections_paginated.name,
118+
collections_paginated.slug,
119+
collections_paginated.description,
120+
collections_paginated.projectCount,
121+
collections_paginated.starred,
122+
collections_paginated.softwareValue,
123+
collections_paginated.contributorCount
117124
order by
118125
{{
119126
column(

0 commit comments

Comments
 (0)