Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
90f7e62f
Unverified
Commit
90f7e62f
authored
10 months ago
by
Uladzimir Havenchyk
Committed by
GitHub
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Optimize getColumnCardinality by using cache correctly (#42664)
parent
fe1f5950
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/visualizations/lib/utils.js
+6
-4
6 additions, 4 deletions
frontend/src/metabase/visualizations/lib/utils.js
with
6 additions
and
4 deletions
frontend/src/metabase/visualizations/lib/utils.js
+
6
−
4
View file @
90f7e62f
...
...
@@ -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
Weak
Map
();
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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment