From aeb3013d7e66fd1e66522c8bb9d2e147c81fb0b6 Mon Sep 17 00:00:00 2001 From: PTR-inc Date: Tue, 18 Feb 2025 14:46:32 +0100 Subject: [PATCH] Use structuredClone instead of parse/stringify --- db.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/db.js b/db.js index 81ea222c..a8db02ce 100644 --- a/db.js +++ b/db.js @@ -699,9 +699,15 @@ module.exports.CreateDB = function (parent, func) { return r; } - // Clone an object (TODO: Make this more efficient) - function Clone(v) { return JSON.parse(JSON.stringify(v)); } - + // Clone an object (TODO: Make this more efficient) >> Use StructuredClone from v17 onward + let Clone; + if (process.versions.node.split('.')[0] >= '17'){ + Clone = function (v) { return structuredClone(v); } + } + else { + Clone = function (v) { return JSON.parse(JSON.stringify(v)); } + } + // Read expiration time from configuration file if (typeof parent.args.dbexpire == 'object') { if (typeof parent.args.dbexpire.events == 'number') { expireEventsSeconds = parent.args.dbexpire.events; }