Skip to content

Commit 11e392d

Browse files
committed
scale down dev instance
1 parent 43f1fda commit 11e392d

File tree

8 files changed

+280
-190
lines changed

8 files changed

+280
-190
lines changed

README.md

Lines changed: 256 additions & 158 deletions
Large diffs are not rendered by default.

src/controllers/versionsController.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,33 @@ const listVersions = async (req, res) => {
2222

2323
let query = firestore.collection('versions');
2424

25-
// Apply technology filter - optimize for multiple technologies
25+
// Apply technology filter
2626
if (params.technology) {
2727
const technologies = convertToArray(params.technology);
2828
if (technologies.length <= 30) {
2929
// Use single query with 'in' operator for up to 30 technologies (Firestore limit)
3030
query = query.where('technology', 'in', technologies);
3131
} else {
32-
// For more than 30 technologies, split into multiple queries and run in parallel
33-
const chunks = [];
34-
for (let i = 0; i < technologies.length; i += 30) {
35-
chunks.push(technologies.slice(i, i + 30));
36-
}
37-
38-
const promises = chunks.map(chunk =>
39-
firestore.collection('versions').where('technology', 'in', chunk).get()
40-
);
41-
42-
const snapshots = await Promise.all(promises);
43-
const data = [];
44-
45-
snapshots.forEach(snapshot => {
46-
snapshot.forEach(doc => {
47-
data.push(doc.data());
48-
});
49-
});
50-
51-
// Cache the result
52-
setCachedQueryResult(cacheKey, data);
53-
54-
res.statusCode = 200;
55-
res.end(JSON.stringify(data));
32+
res.statusCode = 400;
33+
res.end(JSON.stringify({
34+
success: false,
35+
errors: [{ technology: 'Too many technologies specified. Maximum 30 allowed.' }]
36+
}));
5637
return;
5738
}
5839
}
5940

41+
// Apply version filter
42+
if (params.version) {
43+
query = query.where('version', '==', params.version);
44+
}
45+
46+
// Only select requested fields if specified
47+
if (params.fields) {
48+
const requestedFields = params.fields.split(',').map(f => f.trim());
49+
query = query.select(...requestedFields);
50+
}
51+
6052
// Execute single query
6153
const snapshot = await query.get();
6254
const data = [];

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"node": ">=22.0.0"
99
},
1010
"scripts": {
11-
"start": "export DATABASE=tech-report-api-prod &&node index.js",
11+
"start": "export DATABASE=tech-report-api-prod && node index.js",
1212
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
1313
"test:live": "bash ../test-api.sh"
1414
},

src/utils/controllerHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ const getCacheStats = () => {
316316
ttl: CACHE_TTL
317317
},
318318
config: {
319-
maxCacheSize: MAX_CACHE_SIZE,
319+
maxQueryCacheSize: MAX_CACHE_SIZE,
320320
cleanupStrategy: 'size-based-lru'
321321
}
322322
};

terraform/dev/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ provider "google" {
1313

1414
resource "google_api_gateway_api" "api" {
1515
provider = google-beta
16-
api_id = "reports-api"
17-
display_name = "Reports API Gateway"
16+
api_id = "reports-api-dev"
17+
display_name = "Reports API Gateway DEV"
1818
project = var.project
1919
}
2020

terraform/dev/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ variable "google_service_account_api_gateway" {
3030
variable "min_instances" {
3131
description = "(Optional) The limit on the minimum number of function instances that may coexist at a given time."
3232
type = number
33-
default = 1 // TODO: Update this to 0
33+
default = 0
3434
}

terraform/modules/run-service/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ variable "min_instances" {
7171
variable "max_instance_request_concurrency" {
7272
description = "(Optional) The limit on the maximum number of requests that an instance can handle simultaneously. This can be used to control costs when scaling. Defaults to 1."
7373
type = number
74-
default = 18
74+
default = 80
7575
}
7676
variable "environment_variables" {
7777
description = "environment_variables"

terraform/prod/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ provider "google" {
1414
resource "google_api_gateway_api" "api" {
1515
provider = google-beta
1616
api_id = "reports-api-prod"
17-
display_name = "Reports API Gateway"
17+
display_name = "Reports API Gateway PROD"
1818
project = var.project
1919
}
2020

0 commit comments

Comments
 (0)