UNPKG

flexmonster-mongo-connector

Version:

MongoDB connector for Flexmonster Pivot Table and Charts

57 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryConstants = exports.MemoryCalculator = void 0; class MemoryCalculator { static calculateMapDataSize(data) { let bytes = 0; let keySize = 0; let valueSize = 0; data.forEach((value, key) => { keySize = key.length * exports.MemoryConstants.CHARACTER; valueSize = JSON.stringify(value).length * exports.MemoryConstants.CHARACTER; bytes += MemoryCalculator.roundTo8bytes(keySize + valueSize); }); return bytes; } static calculateMemberObjectSize(stringContent = [], numberOfNumericReferences = 0) { let objectSize = 2 * exports.MemoryConstants.REFERENCE; for (let i = 0; i < stringContent.length; i++) { objectSize += exports.MemoryConstants.REFERENCE + exports.MemoryConstants.CHARACTER * stringContent[i].length; } objectSize += (exports.MemoryConstants.REFERENCE + exports.MemoryConstants.NUMBER) * numberOfNumericReferences; return this.roundTo8bytes(objectSize); } static calculateFlatDataSize(flatData) { let dataSize = 2 * exports.MemoryConstants.REFERENCE; dataSize += Object.keys(flatData).length * exports.MemoryConstants.REFERENCE; let fieldsArraySize = 2 * exports.MemoryConstants.REFERENCE; for (let i = 0; i < flatData.fields.length; i++) { fieldsArraySize += 2 * exports.MemoryConstants.REFERENCE + flatData.fields[i]["uniqueName"].length * exports.MemoryConstants.CHARACTER; } let aggsArraySize = 0; if (typeof flatData.aggs !== "undefined") { aggsArraySize += 2 * exports.MemoryConstants.REFERENCE; if (typeof flatData.aggs[0] !== "undefined") { aggsArraySize += 2 * exports.MemoryConstants.REFERENCE + Object.keys(flatData.aggs[0]).length * exports.MemoryConstants.REFERENCE; if (typeof flatData.aggs[0]["value"] !== "undefined") { aggsArraySize += 2 * exports.MemoryConstants.REFERENCE + Object.keys(flatData.aggs[0]["value"]).length * (exports.MemoryConstants.REFERENCE + exports.MemoryConstants.NUMBER); } } } dataSize += fieldsArraySize + aggsArraySize; return this.roundTo8bytes(dataSize); } static roundTo8bytes(notRounded) { const remainder = notRounded % 8; if (remainder === 0) return notRounded; return notRounded - remainder + 8; } } exports.MemoryCalculator = MemoryCalculator; exports.MemoryConstants = { NUMBER: 8, CHARACTER: 2, REFERENCE: 8 }; //# sourceMappingURL=MemoryCalculator.js.map