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
77d1c3c2
Commit
77d1c3c2
authored
6 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Cache rule specificity, remove Schema checkes on the hot path
parent
02aaf687
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/automagic_dashboards/core.clj
+14
-18
14 additions, 18 deletions
src/metabase/automagic_dashboards/core.clj
src/metabase/automagic_dashboards/rules.clj
+6
-0
6 additions, 0 deletions
src/metabase/automagic_dashboards/rules.clj
with
20 additions
and
18 deletions
src/metabase/automagic_dashboards/core.clj
+
14
−
18
View file @
77d1c3c2
...
...
@@ -536,15 +536,11 @@
(
assoc
:score
score
:dataset_query
query
))))))))
(
s/defn
^
:private
rule-specificity
[
rule
:-
rules/Rule
]
(
transduce
(
map
(
comp
count
ancestors
))
+
(
:applies_to
rule
)))
(
s/defn
^
:private
matching-rules
(
defn-
matching-rules
"Return matching rules orderd by specificity.
Most specific is defined as entity type specification the longest ancestor
chain."
[
rules
:-
[
rules/Rule
]
,
{
:keys
[
source
entity
]}]
[
rules
{
:keys
[
source
entity
]}]
(
let
[
table-type
(
or
(
:entity_type
source
)
:entity/GenericTable
)]
(
->>
rules
(
filter
(
fn
[{
:keys
[
applies_to
]}]
...
...
@@ -552,7 +548,7 @@
(
and
(
isa?
table-type
entity-type
)
(
or
(
nil?
field-type
)
(
field-isa?
entity
field-type
))))))
(
sort-by
rule-
specificity
>
))))
(
sort-by
:
specificity
>
))))
(
defn-
linked-tables
"Return all tables accessable from a given table with the paths to get there.
...
...
@@ -642,11 +638,11 @@
vals
(
apply
concat
)))
(
s/
defn
^
:private
make-dashboard
([
root
,
rule
:-
rules/Rule
]
(
defn
-
make-dashboard
([
root
rule
]
(
make-dashboard
root
rule
{
:tables
[(
:source
root
)]
:root
root
}))
([
root
,
rule
:-
rules/Rule,
context
]
([
root
rule
context
]
(
->
rule
(
select-keys
[
:title
:description
:transient_title
:groups
])
(
instantiate-metadata
context
{})
...
...
@@ -883,17 +879,17 @@
(
into
#
{}
(
map
:table_id
)))
link-table?
(
->>
(
db/query
{
:select
[
:table_id
[
:%count.*
:count
]]
:from
[
:metabase_field
]
:where
[
:and
[
:in
:table_id
(
map
u/get-id
tables
)]
:where
[
:and
[
:in
:table_id
(
keys
field-count
)]
[
:in
:special_type
[
"type/PK"
"type/FK"
]]]
:group-by
[
:table_id
]})
(
filter
(
fn
[{
:keys
[
table_id
count
]}]
(
=
count
(
field-count
table_id
))))
(
into
#
{}
(
map
:table_id
)))]
(
for
[
table
tables
]
(
let
[
table-id
(
u/get-id
table
)]
(
assoc
table
:stats
{
:num-fields
(
field-count
table-id
)
:list-like?
(
boolean
(
list-like?
table-id
))
:link-table?
(
boolean
(
link-table?
table-id
))})))))
(
for
[
table
tables
]
(
let
[
table-id
(
u/get-id
table
)]
(
assoc
table
:stats
{
:num-fields
(
field-count
table-id
0
)
:list-like?
(
boolean
(
list-like?
table-id
))
:link-table?
(
boolean
(
link-table?
table-id
))})))))
(
def
^
:private
^
:const
^
Long
max-candidate-tables
"Maximal number of tables per schema shown in `candidate-tables`."
...
...
@@ -918,7 +914,7 @@
schema
(
concat
[
:schema
schema
])))
(
filter
mi/can-read?
)
enhance-table-stats
(
remove
(
comp
(
some-fn
:link-table?
:list-like?
)
:stats
))
(
remove
(
comp
(
some-fn
:link-table?
:list-like?
(
comp
zero?
:num-fields
)
)
:stats
))
(
map
(
fn
[
table
]
(
let
[
root
(
->root
table
)
rule
(
->>
root
...
...
@@ -927,7 +923,7 @@
dashboard
(
make-dashboard
root
rule
)]
{
:url
(
format
"%stable/%s"
public-endpoint
(
u/get-id
table
))
:title
(
:full-name
root
)
:score
(
+
(
math/sq
(
rule-
specificity
rule
))
:score
(
+
(
math/sq
(
:
specificity
rule
))
(
math/log
(
->
table
:stats
:num-fields
)))
:description
(
:description
dashboard
)
:table
table
...
...
This diff is collapsed.
Click to expand it.
src/metabase/automagic_dashboards/rules.clj
+
6
−
0
View file @
77d1c3c2
...
...
@@ -189,6 +189,7 @@
(
constrained-all
{(
s/required-key
:title
)
s/Str
(
s/required-key
:rule
)
s/Str
(
s/required-key
:specificity
)
s/Int
(
s/optional-key
:cards
)
[
Card
]
(
s/optional-key
:dimensions
)
[
Dimension
]
(
s/optional-key
:applies_to
)
AppliesTo
...
...
@@ -278,6 +279,10 @@
(
def
^
:private
^
{
:arglists
'
([
f
])}
file->entity-type
(
comp
(
partial
re-find
#
".+(?=\.yaml$)"
)
str
(
memfn
^
Path
getFileName
)))
(
defn-
specificity
[
rule
]
(
transduce
(
map
(
comp
count
ancestors
))
+
(
:applies_to
rule
)))
(
defn-
load-rule
[
^
Path
f
]
(
try
...
...
@@ -288,6 +293,7 @@
yaml/parse-string
(
assoc
:rule
entity-type
)
(
update
:applies_to
#
(
or
%
entity-type
))
(
as->
rule
(
assoc
rule
:specificity
(
specificity
rule
)))
rules-validator
))
(
catch
Exception
e
(
log/errorf
(
trs
"Error parsing %s:\n%s"
)
...
...
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