Skip to content

Commit 03e052e

Browse files
committed
feat: update CWV distribution query to handle 'ALL' technology case and refactor related logic
1 parent ceda97d commit 03e052e

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"node": ">=22.0.0"
99
},
1010
"scripts": {
11-
"start": "DATABASE=tech-report-api-prod functions-framework --target=app",
11+
"function": "DATABASE=tech-report-api-prod functions-framework --target=app",
1212
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
1313
"test:live": "bash ../test-api.sh",
1414
"build": "docker build -t report-api .",
15-
"run": "docker run -p 8080:8080 report-api"
15+
"docker": "docker run -p 8080:8080 report-api"
1616
},
1717
"dependencies": {
1818
"@google-cloud/bigquery": "^7.9.1",

src/utils/reportService.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ export const queryReport = async (reportType, params = {}) => {
156156
};
157157

158158
export const queryCWVDistribution = async ({ technology, date, geo = 'ALL', rank = null }) => {
159-
const technologies = convertToArray(technology);
159+
const allTechnologies = !technology || technology === 'ALL';
160+
const technologies = allTechnologies ? [] : convertToArray(technology);
161+
const techClause = allTechnologies ? '' : 'AND t.technology IN UNNEST(@technologies)';
160162
const rankParam = (rank !== null && rank !== 'ALL') ? parseInt(rank, 10) : null;
161163
const rankClause = rankParam !== null ? 'AND rank <= @rank' : '';
162164

@@ -169,8 +171,8 @@ export const queryCWVDistribution = async ({ technology, date, geo = 'ALL', rank
169171
httparchive.crawl.pages,
170172
UNNEST(technologies) AS t
171173
WHERE
172-
date = @date AND
173-
t.technology IN UNNEST(@technologies)
174+
date = @date
175+
${techClause}
174176
${rankClause}
175177
), metrics AS (
176178
SELECT
@@ -250,13 +252,13 @@ ORDER BY
250252
const [rows] = await bigquery.query({
251253
query,
252254
params: {
253-
technologies,
255+
...(!allTechnologies && { technologies }),
254256
date,
255257
geo,
256258
...(rankParam !== null && { rank: rankParam }),
257259
},
258260
types: {
259-
technologies: ['STRING'],
261+
...(!allTechnologies && { technologies: ['STRING'] }),
260262
date: 'STRING',
261263
geo: 'STRING',
262264
...(rankParam !== null && { rank: 'INT64' }),

0 commit comments

Comments
 (0)