@jsonjoy.com/reactive-rpc
Version:
Reactive-RPC is a library for building reactive APIs over WebSocket, HTTP, and other RPCs.
19 lines • 832 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.storageSpaceReclaimDecision = void 0;
const KILOBYTE = 1024;
const MEGABYTE = KILOBYTE * KILOBYTE;
const storageSpaceReclaimDecision = (promises, isGoodTime = () => Math.random() < 0.1, threshold = 300 * MEGABYTE) => async () => {
if (!isGoodTime())
return 0;
const stats = await promises.statfs('/');
const availableBytes = stats.bavail * stats.bsize;
if (availableBytes > threshold)
return 0;
const avgDocSize = 30 * KILOBYTE;
const blocksToDelete = Math.ceil((threshold - availableBytes) / avgDocSize);
const blocksToDeleteClamped = Math.min(100, blocksToDelete);
return blocksToDeleteClamped;
};
exports.storageSpaceReclaimDecision = storageSpaceReclaimDecision;
//# sourceMappingURL=util.js.map
;