From dcb5c3f85db74512dcad624eb8208e0e1bb283f5 Mon Sep 17 00:00:00 2001 From: Nick Gavalas Date: Sun, 12 Mar 2023 00:30:47 -0600 Subject: [PATCH] move cache to WeakMap --- lib/registry.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/registry.js b/lib/registry.js index 2169b66f..97203eed 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -219,14 +219,16 @@ function formatLabels(labels) { ); } +const sharedLabelCache = new WeakMap(); function flattenSharedLabels(labels) { - if (labels.__flattened_internal) { - return labels.__flattened_internal; + const cached = sharedLabelCache.get(labels); + if (cached) { + return cached; } const formattedLabels = formatLabels(labels); const flattened = formattedLabels.join(','); - Object.defineProperty(labels, '__flattened_internal', { value: flattened }); + sharedLabelCache.set(labels, flattened); return flattened; } function escapeLabelValue(str) {