Skip to content

Commit 4e47c8b

Browse files
committed
clean: cleanup utils directory
1 parent d5ecac4 commit 4e47c8b

File tree

9 files changed

+18
-99
lines changed

9 files changed

+18
-99
lines changed

src/backend/src/util/context.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class Context {
5252
);
5353
}
5454

55-
// x = globalThis.root_context ?? this.create({});
5655
x = this.root.sub({}, this.USE_NAME_FALLBACK);
5756
}
5857
if ( x && k ) return x.get(k);
@@ -180,7 +179,6 @@ class Context {
180179
});
181180
}
182181
abind (cb) {
183-
const als = this.constructor.contextAsyncLocalStorage;
184182
return async (...args) => {
185183
return await this.arun(async () => {
186184
return await cb(...args);

src/backend/src/util/fuzz.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
*/
19-
// function fuzz_number(n) {
20-
// if (n === 0) return 0;
21-
22-
// // let randomized = n + (Math.random() - 0.5) * n * 0.2;
23-
// let randomized = n;
24-
// let magnitude = Math.floor(Math.log10(randomized));
25-
// let factor = Math.pow(10, magnitude);
26-
// return Math.round(randomized / factor) * factor;
27-
// }
2819

2920
function fuzz_number(num) {
3021
// If the number is 0, then return 0
@@ -46,47 +37,6 @@ function fuzz_number(num) {
4637
return Math.round(num / factor) * factor;
4738
}
4839

49-
// function fuzz_number(number) {
50-
// if (isNaN(number)) {
51-
// return 'Invalid number';
52-
// }
53-
54-
// let formattedNumber;
55-
// if (number >= 1000000) {
56-
// // For millions, we want to show one decimal place
57-
// formattedNumber = (number / 1000000).toFixed(0) + 'm';
58-
// } else if (number >= 1000) {
59-
// // For thousands, we want to show one decimal place
60-
// formattedNumber = (number / 1000).toFixed(0) + 'k';
61-
// } else if (number >= 500) {
62-
// // For hundreds, we want to show no decimal places
63-
// formattedNumber = '500+';
64-
// } else if (number >= 100) {
65-
// // For hundreds, we want to show no decimal places
66-
// formattedNumber = '100+';
67-
// } else if (number >= 50) {
68-
// // For hundreds, we want to show no decimal places
69-
// formattedNumber = '50+';
70-
// } else if (number >= 10) {
71-
// // For hundreds, we want to show no decimal places
72-
// formattedNumber = '10+';
73-
// }
74-
// else {
75-
// // For numbers less than 10, we show the number as is.
76-
// formattedNumber = '1+';
77-
// }
78-
79-
// // If the decimal place is 0 (e.g., 5.0k), we remove the decimal part (to have 5k instead)
80-
// formattedNumber = formattedNumber.replace(/\.0(?=[k|m])/, '');
81-
82-
// // Append the plus sign for numbers 1000 and greater, denoting the number is 'this value or more'.
83-
// if (number >= 1000) {
84-
// formattedNumber += '+';
85-
// }
86-
87-
// return formattedNumber;
88-
// }
89-
9040
module.exports = {
9141
fuzz_number
9242
};

src/backend/src/util/lockutil.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
const { TeePromise } = require('@heyputer/putility').libs.promise;
2020

21+
/**
22+
* RWLock is a read-write lock that allows multiple readers or a single writer.
23+
*/
2124
class RWLock {
2225
static TYPE_READ = Symbol('read');
2326
static TYPE_WRITE = Symbol('write');
@@ -45,11 +48,6 @@ class RWLock {
4548
this.check_queue_();
4649
}
4750
check_queue_ () {
48-
// console.log('check_queue_', {
49-
// readers_: this.readers_,
50-
// writer_: this.writer_,
51-
// queue: this.queue.map(item => item.type),
52-
// });
5351
if ( this.queue.length === 0 ) {
5452
if ( this.readers_ === 0 && ! this.writer_ ) {
5553
this.on_empty_();

src/backend/src/util/otelutil.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class ParallelTasks {
100100
return;
101101
}
102102

103-
// const span = this.tracer.startSpan(name);
104103
this.promises.push(this.run_(name, fn));
105104
}
106105

src/backend/src/util/queuing.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/backend/src/util/retryutil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const simple_retry = async function simple_retry (func, max_tries, interval) {
5252
};
5353

5454
const poll = async function poll({ poll_fn, schedule_fn }) {
55-
let delay = undefined;
55+
let delay;
5656

5757
while ( true ) {
5858
const is_done = await poll_fn();

src/backend/src/util/streamutil.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
const { PassThrough, Readable, Transform } = require('stream');
2020
const { TeePromise } = require('@heyputer/putility').libs.promise;
21-
const { EWMA } = require('./opmath');
2221

2322
class StreamBuffer extends TeePromise {
2423
constructor () {
@@ -47,6 +46,15 @@ const stream_to_the_void = stream => {
4746
stream.on('error', () => {});
4847
};
4948

49+
/**
50+
* This will split a stream (on the read side) into `n` streams.
51+
* The slowest reader will determine the speed the the source stream
52+
* is consumed at to avoid buffering.
53+
*
54+
* @param {*} source
55+
* @param {*} n
56+
* @returns
57+
*/
5058
const pausing_tee = (source, n) => {
5159
const { PassThrough } = require('stream');
5260

@@ -59,39 +67,31 @@ const pausing_tee = (source, n) => {
5967
streams_.push(stream);
6068
stream.on('drain', () => {
6169
ready_[i] = true;
62-
// console.log(source.id, 'PR :: drain from reader', i, ready_);
6370
if ( first_ ) {
6471
source.resume();
6572
first_ = false;
6673
}
6774
if (ready_.every(v => !! v)) source.resume();
6875
});
69-
// stream.on('newListener', (event, listener) => {
70-
// console.log('PR :: newListener', i, event, listener);
71-
// });
7276
}
7377

7478
source.on('data', (chunk) => {
75-
// console.log(source.id, 'PT :: data from source', chunk.length);
7679
ready_.forEach((v, i) => {
7780
ready_[i] = streams_[i].write(chunk);
7881
});
7982
if ( ! ready_.every(v => !! v) ) {
80-
// console.log('PT :: pausing source', ready_);
8183
source.pause();
8284
return;
8385
}
8486
});
8587

8688
source.on('end', () => {
87-
// console.log(source.id, 'PT :: end from source');
8889
for ( let i=0 ; i < n ; i++ ) {
8990
streams_[i].end();
9091
}
9192
});
9293

9394
source.on('error', (err) => {
94-
// console.log(source.id, 'PT :: error from source', err);
9595
for ( let i=0 ; i < n ; i++ ) {
9696
streams_[i].emit('error', err);
9797
}
@@ -100,6 +100,9 @@ const pausing_tee = (source, n) => {
100100
return streams_;
101101
};
102102

103+
/**
104+
* A debugging stream transform that logs the data it receives.
105+
*/
103106
class LoggingStream extends Transform {
104107
constructor(options) {
105108
super(options);
@@ -431,9 +434,7 @@ async function* chunk_stream(
431434
offset += amount;
432435

433436
while (offset >= chunk_size) {
434-
console.log('start yield');
435437
yield buffer;
436-
console.log('end yield');
437438

438439
buffer = Buffer.alloc(chunk_size);
439440
offset = 0;
@@ -449,13 +450,8 @@ async function* chunk_stream(
449450

450451
if ( chunk_time_ewma !== null ) {
451452
const chunk_time = chunk_time_ewma.get();
452-
// const sleep_time = chunk_size * chunk_time;
453453
const sleep_time = (chunk.length / chunk_size) * chunk_time / 2;
454-
// const sleep_time = (amount / chunk_size) * chunk_time;
455-
// const sleep_time = (amount / chunk_size) * chunk_time;
456-
console.log(`start sleep ${amount} / ${chunk_size} * ${chunk_time} = ${sleep_time}`);
457454
await new Promise(resolve => setTimeout(resolve, sleep_time));
458-
console.log('end sleep');
459455
}
460456
}
461457

src/backend/src/util/validutil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const valid_file_size = v => {
2121
if ( ! Number.isInteger(v) ) {
2222
return { ok: false, v };
2323
}
24-
if ( ! (v >= 0) ) {
24+
if ( v < 0 ) {
2525
return { ok: false, v };
2626
}
2727
return { ok: true, v };

src/backend/src/util/workutil.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class WorkList {
2828

2929
clear_invalid () {
3030
const new_items = [];
31-
for ( let i=0 ; i < this.items.length ; i++ ) {
32-
const item = this.items[i];
31+
for ( const item of this.items ) {
3332
if ( item.invalid ) continue;
3433
new_items.push(item);
3534
}

0 commit comments

Comments
 (0)