Skip to content

Switch back dev and prod #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
421 changes: 260 additions & 161 deletions README.md

Large diffs are not rendered by default.

42 changes: 17 additions & 25 deletions src/controllers/versionsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,33 @@ const listVersions = async (req, res) => {

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

// Apply technology filter - optimize for multiple technologies
// Apply technology filter
if (params.technology) {
const technologies = convertToArray(params.technology);
if (technologies.length <= 30) {
// Use single query with 'in' operator for up to 30 technologies (Firestore limit)
query = query.where('technology', 'in', technologies);
} else {
// For more than 30 technologies, split into multiple queries and run in parallel
const chunks = [];
for (let i = 0; i < technologies.length; i += 30) {
chunks.push(technologies.slice(i, i + 30));
}

const promises = chunks.map(chunk =>
firestore.collection('versions').where('technology', 'in', chunk).get()
);

const snapshots = await Promise.all(promises);
const data = [];

snapshots.forEach(snapshot => {
snapshot.forEach(doc => {
data.push(doc.data());
});
});

// Cache the result
setCachedQueryResult(cacheKey, data);

res.statusCode = 200;
res.end(JSON.stringify(data));
res.statusCode = 400;
res.end(JSON.stringify({
success: false,
errors: [{ technology: 'Too many technologies specified. Maximum 30 allowed.' }]
}));
return;
}
}

// Apply version filter
if (params.version) {
query = query.where('version', '==', params.version);
}

// Only select requested fields if specified
if (params.fields) {
const requestedFields = params.fields.split(',').map(f => f.trim());
query = query.select(...requestedFields);
}

// Execute single query
const snapshot = await query.get();
const data = [];
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node": ">=22.0.0"
},
"scripts": {
"start": "export DATABASE=tech-report-api-prod &&node index.js",
"start": "export DATABASE=tech-report-api-prod && node index.js",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test:live": "bash ../test-api.sh"
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/controllerHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const getCacheStats = () => {
ttl: CACHE_TTL
},
config: {
maxCacheSize: MAX_CACHE_SIZE,
maxQueryCacheSize: MAX_CACHE_SIZE,
cleanupStrategy: 'size-based-lru'
}
};
Expand Down
4 changes: 2 additions & 2 deletions terraform/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ provider "google" {

resource "google_api_gateway_api" "api" {
provider = google-beta
api_id = "reports-api"
display_name = "Reports API Gateway"
api_id = "reports-api-dev"
display_name = "Reports API Gateway DEV"
project = var.project
}

Expand Down
2 changes: 1 addition & 1 deletion terraform/dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ variable "google_service_account_api_gateway" {
variable "min_instances" {
description = "(Optional) The limit on the minimum number of function instances that may coexist at a given time."
type = number
default = 1 // TODO: Update this to 0
default = 0
}
2 changes: 1 addition & 1 deletion terraform/modules/run-service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ variable "min_instances" {
variable "max_instance_request_concurrency" {
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."
type = number
default = 18
default = 80
}
variable "environment_variables" {
description = "environment_variables"
Expand Down
2 changes: 1 addition & 1 deletion terraform/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ provider "google" {
resource "google_api_gateway_api" "api" {
provider = google-beta
api_id = "reports-api-prod"
display_name = "Reports API Gateway"
display_name = "Reports API Gateway PROD"
project = var.project
}

Expand Down
Loading