UNPKG

json-crdt-server

Version:

JSON CRDT server and syncing local-first browser client

19 lines (18 loc) 800 B
"use strict"; 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;