Skip to content
Snippets Groups Projects
Unverified Commit 90f7e62f authored by Uladzimir Havenchyk's avatar Uladzimir Havenchyk Committed by GitHub
Browse files

Optimize getColumnCardinality by using cache correctly (#42664)

parent fe1f5950
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import { t } from "ttag";
import _ from "underscore";
import { isNotNull } from "metabase/lib/types";
import { getColumnKey } from "metabase-lib/v1/queries/utils/get-column-key";
import { isDimension, isMetric, isDate } from "metabase-lib/v1/types/utils/isa";
export const MAX_SERIES = 100;
......@@ -206,21 +207,22 @@ export function colorShade(hex, shade = 0) {
}
// cache computed cardinalities in a weak map since they are computationally expensive
const cardinalityCache = new WeakMap();
const cardinalityCache = new Map();
export function getColumnCardinality(cols, rows, index) {
const col = cols[index];
if (!cardinalityCache.has(col)) {
const key = getColumnKey(col);
if (!cardinalityCache.has(key)) {
const dataset = crossfilter(rows);
cardinalityCache.set(
col,
key,
dataset
.dimension(d => d[index])
.group()
.size(),
);
}
return cardinalityCache.get(col);
return cardinalityCache.get(key);
}
const extentCache = new WeakMap();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment