Skip to content
Open
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
13 changes: 13 additions & 0 deletions lib/algos/list/delimiterCurrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ class DelimiterCurrent extends DelimiterMaster {
};
}

// Limit the number of documents MongoDB returns to bound the
// in-memory sort when lifecycle indexes are used (these indexes
// order by value.last-modified, forcing a re-sort on _id). Without
// a limit, MongoDB must sort all matching documents — which can
// exceed the 100MB memory cap and spill to disk.
// We use maxScannedLifecycleListingEntries (default 10,000) as the
// bound because it counts documents scanned, which maps directly
// to cursor documents regardless of bucket format (v0 or v1).
// The +1 allows the listing algorithm to detect truncation.
if (this.maxScannedLifecycleListingEntries) {
params.limit = this.maxScannedLifecycleListingEntries + 1;
}

return params;
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/algos/list/delimiterCurrent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function getListingKey(key, vFormat) {
},
gt: getListingKey('premark', v),
lt: getListingKey('prf', v),
limit: maxScannedLifecycleListingEntries + 1,
};
assert.deepStrictEqual(delimiter.genMDParams(), expectedParams);
assert.strictEqual(delimiter.maxScannedLifecycleListingEntries, 2);
Expand Down
Loading