Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Nov 22, 2023
2 parents 654e3d9 + 0ec8ed4 commit 92b41ed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions frameworks/JavaScript/nodejs/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const cluster = require('node:cluster');
const { availableParallelism } = require('node:os');
const numCPUs = availableParallelism();

process.env.NODE_HANDLER = 'postgres';

Expand All @@ -13,18 +14,18 @@ if (process.env.TFB_TEST_NAME === 'nodejs-mongodb') {
process.env.NODE_HANDLER = 'mysql-raw';
} else if (process.env.TFB_TEST_NAME === 'nodejs-postgres') {
process.env.NODE_HANDLER = 'sequelize-postgres';
}else if (process.env.TFB_TEST_NAME === 'nodejs-postgresjs-raw') {
} else if (process.env.TFB_TEST_NAME === 'nodejs-postgresjs-raw') {
process.env.NODE_HANDLER = 'postgres';
}

if (cluster.isPrimary) {
if (numCPUs > 1 && cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`);

// Fork workers.
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion frameworks/JavaScript/nodejs/create-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Forked workers will run this code when found to not be
// the master of the cluster.

const http = require('http');
const http = require('node:http');
const parseurl = require('parseurl'); // faster than native nodejs url package

// Initialize routes & their handlers (once)
Expand Down
12 changes: 6 additions & 6 deletions frameworks/JavaScript/nodejs/handlers/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const dbfind = async (id) =>
(arr) => arr[0]
);

const dbbulkUpdate = async (worlds) =>
const dbbulkUpdate = async (worlds) => {
const sorted = sql(worlds
.map((world) => [world.id, world.randomNumber])
.sort((a, b) => (a[0] < b[0] ? -1 : 1)));
await sql`UPDATE world SET randomNumber = (update_data.randomNumber)::int
FROM (VALUES ${sql(
worlds
.map((world) => [world.id, world.randomNumber])
.sort((a, b) => (a[0] < b[0] ? -1 : 1))
)}) AS update_data (id, randomNumber)
FROM (VALUES ${sorted}) AS update_data (id, randomNumber)
WHERE world.id = (update_data.id)::int`;
};

const dbgetAllWorlds = async () => sql`SELECT id, randomNumber FROM world`;

Expand Down
2 changes: 1 addition & 1 deletion frameworks/Rust/gotham/gotham.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.60
FROM rust:1.65

WORKDIR /gotham
COPY ./src ./src
Expand Down

0 comments on commit 92b41ed

Please sign in to comment.