-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove max Content-Length middleware (#16)
Also removes the memory budget code (which has no bearing on actual memory usage!).
- Loading branch information
Alan Shaw
authored
Oct 21, 2022
1 parent
5e205be
commit bf11d0c
Showing
9 changed files
with
117 additions
and
249 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
const MAX_BYTES_BETWEEN = 1024 * 1024 * 2 | ||
const MAX_BATCH_SIZE = 10 | ||
|
||
export class BlockBatch { | ||
/** @type {number[]} */ | ||
#offsets = [] | ||
/** | ||
* @typedef {import('multiformats').CID} CID | ||
* @typedef {{ carCid: CID, blockCid: CID, offset: number }} BatchItem | ||
* @typedef {{ add: (i: BatchItem) => void, next: () => BatchItem[] }} BlockBatcher | ||
*/ | ||
|
||
/** | ||
* Add an offset to the batch | ||
* @param {number} offset | ||
*/ | ||
add (offset) { | ||
this.#offsets.push(offset) | ||
/** | ||
* Batcher for blocks in CARs. Batches are grouped by CAR CID and blocks are | ||
* returned in batches in the order they were inserted. | ||
* @implements {BlockBatcher} | ||
*/ | ||
export class OrderedCarBlockBatcher { | ||
/** @type {BatchItem[]} */ | ||
#queue = [] | ||
|
||
/** @param {BatchItem} item */ | ||
add (item) { | ||
this.#queue.push(item) | ||
} | ||
|
||
next () { | ||
const offsets = this.#offsets // .sort((a, b) => a - b) | ||
if (!offsets.length) return | ||
const batch = [] | ||
let last = offsets[0] | ||
const queue = this.#queue | ||
let prevItem = queue.shift() | ||
if (!prevItem) return [] | ||
const batch = [prevItem] | ||
while (true) { | ||
const offset = offsets.shift() | ||
if (!offset) break | ||
if (offset - last >= MAX_BYTES_BETWEEN) { | ||
offsets.unshift(offset) // not in this batch, return to pile | ||
const item = queue.at(0) | ||
if (!item) break | ||
if (item.carCid.toString() !== prevItem.carCid.toString() || item.offset - prevItem.offset >= MAX_BYTES_BETWEEN) { | ||
break | ||
} | ||
batch.push(offset) | ||
batch.push(item) | ||
queue.shift() // remove from the queue | ||
if (batch.length >= MAX_BATCH_SIZE) break | ||
last = offset | ||
prevItem = item | ||
} | ||
this.#offsets = offsets | ||
return batch | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.