diff --git a/src/backend/src/util/context.js b/src/backend/src/util/context.js
index f7a2ffcbd..15fdb941b 100644
--- a/src/backend/src/util/context.js
+++ b/src/backend/src/util/context.js
@@ -52,7 +52,6 @@ class Context {
);
}
- // x = globalThis.root_context ?? this.create({});
x = this.root.sub({}, this.USE_NAME_FALLBACK);
}
if ( x && k ) return x.get(k);
@@ -180,7 +179,6 @@ class Context {
});
}
abind (cb) {
- const als = this.constructor.contextAsyncLocalStorage;
return async (...args) => {
return await this.arun(async () => {
return await cb(...args);
diff --git a/src/backend/src/util/fuzz.js b/src/backend/src/util/fuzz.js
index b76763782..56e120029 100644
--- a/src/backend/src/util/fuzz.js
+++ b/src/backend/src/util/fuzz.js
@@ -16,15 +16,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-// function fuzz_number(n) {
-// if (n === 0) return 0;
-
-// // let randomized = n + (Math.random() - 0.5) * n * 0.2;
-// let randomized = n;
-// let magnitude = Math.floor(Math.log10(randomized));
-// let factor = Math.pow(10, magnitude);
-// return Math.round(randomized / factor) * factor;
-// }
function fuzz_number(num) {
// If the number is 0, then return 0
@@ -46,47 +37,6 @@ function fuzz_number(num) {
return Math.round(num / factor) * factor;
}
-// function fuzz_number(number) {
-// if (isNaN(number)) {
-// return 'Invalid number';
-// }
-
-// let formattedNumber;
-// if (number >= 1000000) {
-// // For millions, we want to show one decimal place
-// formattedNumber = (number / 1000000).toFixed(0) + 'm';
-// } else if (number >= 1000) {
-// // For thousands, we want to show one decimal place
-// formattedNumber = (number / 1000).toFixed(0) + 'k';
-// } else if (number >= 500) {
-// // For hundreds, we want to show no decimal places
-// formattedNumber = '500+';
-// } else if (number >= 100) {
-// // For hundreds, we want to show no decimal places
-// formattedNumber = '100+';
-// } else if (number >= 50) {
-// // For hundreds, we want to show no decimal places
-// formattedNumber = '50+';
-// } else if (number >= 10) {
-// // For hundreds, we want to show no decimal places
-// formattedNumber = '10+';
-// }
-// else {
-// // For numbers less than 10, we show the number as is.
-// formattedNumber = '1+';
-// }
-
-// // If the decimal place is 0 (e.g., 5.0k), we remove the decimal part (to have 5k instead)
-// formattedNumber = formattedNumber.replace(/\.0(?=[k|m])/, '');
-
-// // Append the plus sign for numbers 1000 and greater, denoting the number is 'this value or more'.
-// if (number >= 1000) {
-// formattedNumber += '+';
-// }
-
-// return formattedNumber;
-// }
-
module.exports = {
fuzz_number
};
diff --git a/src/backend/src/util/lockutil.js b/src/backend/src/util/lockutil.js
index dde83572b..60c8b1a83 100644
--- a/src/backend/src/util/lockutil.js
+++ b/src/backend/src/util/lockutil.js
@@ -18,6 +18,9 @@
*/
const { TeePromise } = require('@heyputer/putility').libs.promise;
+/**
+ * RWLock is a read-write lock that allows multiple readers or a single writer.
+ */
class RWLock {
static TYPE_READ = Symbol('read');
static TYPE_WRITE = Symbol('write');
@@ -45,11 +48,6 @@ class RWLock {
this.check_queue_();
}
check_queue_ () {
- // console.log('check_queue_', {
- // readers_: this.readers_,
- // writer_: this.writer_,
- // queue: this.queue.map(item => item.type),
- // });
if ( this.queue.length === 0 ) {
if ( this.readers_ === 0 && ! this.writer_ ) {
this.on_empty_();
diff --git a/src/backend/src/util/otelutil.js b/src/backend/src/util/otelutil.js
index e8aef304f..431d820f7 100644
--- a/src/backend/src/util/otelutil.js
+++ b/src/backend/src/util/otelutil.js
@@ -100,7 +100,6 @@ class ParallelTasks {
return;
}
- // const span = this.tracer.startSpan(name);
this.promises.push(this.run_(name, fn));
}
diff --git a/src/backend/src/util/queuing.js b/src/backend/src/util/queuing.js
deleted file mode 100644
index 47955c28d..000000000
--- a/src/backend/src/util/queuing.js
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2024 Puter Technologies Inc.
- *
- * This file is part of Puter.
- *
- * Puter is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published
- * by the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-class QueueBatcher {
- //
-}
diff --git a/src/backend/src/util/retryutil.js b/src/backend/src/util/retryutil.js
index 0bdc614f1..dfb4ae0dd 100644
--- a/src/backend/src/util/retryutil.js
+++ b/src/backend/src/util/retryutil.js
@@ -52,7 +52,7 @@ const simple_retry = async function simple_retry (func, max_tries, interval) {
};
const poll = async function poll({ poll_fn, schedule_fn }) {
- let delay = undefined;
+ let delay;
while ( true ) {
const is_done = await poll_fn();
diff --git a/src/backend/src/util/streamutil.js b/src/backend/src/util/streamutil.js
index bd06b7af0..d095b342c 100644
--- a/src/backend/src/util/streamutil.js
+++ b/src/backend/src/util/streamutil.js
@@ -18,7 +18,6 @@
*/
const { PassThrough, Readable, Transform } = require('stream');
const { TeePromise } = require('@heyputer/putility').libs.promise;
-const { EWMA } = require('./opmath');
class StreamBuffer extends TeePromise {
constructor () {
@@ -47,6 +46,15 @@ const stream_to_the_void = stream => {
stream.on('error', () => {});
};
+/**
+ * This will split a stream (on the read side) into `n` streams.
+ * The slowest reader will determine the speed the the source stream
+ * is consumed at to avoid buffering.
+ *
+ * @param {*} source
+ * @param {*} n
+ * @returns
+ */
const pausing_tee = (source, n) => {
const { PassThrough } = require('stream');
@@ -59,39 +67,31 @@ const pausing_tee = (source, n) => {
streams_.push(stream);
stream.on('drain', () => {
ready_[i] = true;
- // console.log(source.id, 'PR :: drain from reader', i, ready_);
if ( first_ ) {
source.resume();
first_ = false;
}
if (ready_.every(v => !! v)) source.resume();
});
- // stream.on('newListener', (event, listener) => {
- // console.log('PR :: newListener', i, event, listener);
- // });
}
source.on('data', (chunk) => {
- // console.log(source.id, 'PT :: data from source', chunk.length);
ready_.forEach((v, i) => {
ready_[i] = streams_[i].write(chunk);
});
if ( ! ready_.every(v => !! v) ) {
- // console.log('PT :: pausing source', ready_);
source.pause();
return;
}
});
source.on('end', () => {
- // console.log(source.id, 'PT :: end from source');
for ( let i=0 ; i < n ; i++ ) {
streams_[i].end();
}
});
source.on('error', (err) => {
- // console.log(source.id, 'PT :: error from source', err);
for ( let i=0 ; i < n ; i++ ) {
streams_[i].emit('error', err);
}
@@ -100,6 +100,9 @@ const pausing_tee = (source, n) => {
return streams_;
};
+/**
+ * A debugging stream transform that logs the data it receives.
+ */
class LoggingStream extends Transform {
constructor(options) {
super(options);
@@ -431,9 +434,7 @@ async function* chunk_stream(
offset += amount;
while (offset >= chunk_size) {
- console.log('start yield');
yield buffer;
- console.log('end yield');
buffer = Buffer.alloc(chunk_size);
offset = 0;
@@ -449,13 +450,8 @@ async function* chunk_stream(
if ( chunk_time_ewma !== null ) {
const chunk_time = chunk_time_ewma.get();
- // const sleep_time = chunk_size * chunk_time;
const sleep_time = (chunk.length / chunk_size) * chunk_time / 2;
- // const sleep_time = (amount / chunk_size) * chunk_time;
- // const sleep_time = (amount / chunk_size) * chunk_time;
- console.log(`start sleep ${amount} / ${chunk_size} * ${chunk_time} = ${sleep_time}`);
await new Promise(resolve => setTimeout(resolve, sleep_time));
- console.log('end sleep');
}
}
diff --git a/src/backend/src/util/validutil.js b/src/backend/src/util/validutil.js
index cb4a5f255..fe64fddae 100644
--- a/src/backend/src/util/validutil.js
+++ b/src/backend/src/util/validutil.js
@@ -21,7 +21,7 @@ const valid_file_size = v => {
if ( ! Number.isInteger(v) ) {
return { ok: false, v };
}
- if ( ! (v >= 0) ) {
+ if ( v < 0 ) {
return { ok: false, v };
}
return { ok: true, v };
diff --git a/src/backend/src/util/workutil.js b/src/backend/src/util/workutil.js
index 644a4b976..d1d86092b 100644
--- a/src/backend/src/util/workutil.js
+++ b/src/backend/src/util/workutil.js
@@ -28,8 +28,7 @@ class WorkList {
clear_invalid () {
const new_items = [];
- for ( let i=0 ; i < this.items.length ; i++ ) {
- const item = this.items[i];
+ for ( const item of this.items ) {
if ( item.invalid ) continue;
new_items.push(item);
}