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
5419fad5
Commit
5419fad5
authored
7 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Cache fKs for filters
parent
f442539b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/automagic_dashboards/GenericTable.yaml
+1
-1
1 addition, 1 deletion
resources/automagic_dashboards/GenericTable.yaml
src/metabase/automagic_dashboards/filters.clj
+30
-26
30 additions, 26 deletions
src/metabase/automagic_dashboards/filters.clj
with
31 additions
and
27 deletions
resources/automagic_dashboards/GenericTable.yaml
+
1
−
1
View file @
5419fad5
title
:
[[
GenericTable
]]
exploration
title
:
"
[[GenericTable]]
exploration
"
description
:
Potentially interesting metrics about [[GenericTable]] by things like time, place, and category.
metrics
:
-
Count
:
...
...
This diff is collapsed.
Click to expand it.
src/metabase/automagic_dashboards/filters.clj
+
30
−
26
View file @
5419fad5
...
...
@@ -31,22 +31,22 @@
(
isa?
special_type
:type/Category
)
(
field/unix-timestamp?
field
))))))
(
defn-
find-fk
[
from-
table
to-
field
]
(
->>
(
db/select
[
Field
:id
:fk_target_field_id
]
(
defn-
build-fk-map
[
table
s
field
]
(
->>
(
db/select
[
Field
:id
:fk_target_field_id
:table_id
]
:fk_target_field_id
[
:not=
nil
]
:table_id
from-table
)
(
filter
(
comp
#
{(
:table_id
to-field
)}
:table_id
Field
:fk_target_field_id
))
(
map
:id
)))
:table_id
[
:in
tables
])
(
filter
(
comp
#
{(
:table_id
field
)}
:table_id
Field
:fk_target_field_id
))
(
group-by
:table_id
)
(
keep
(
fn
[[
_
[
fk
&
fks
]]]
;; Bail out if there is more than one FK from the same table
(
when
(
empty?
fks
)
[(
:table_id
fk
)
[
:fk->
(
:id
fk
)
(
:id
field
)]])))
(
into
{(
:table_id
field
)
[
:field-id
(
:id
field
)]})))
(
defn-
filter-for-card
[
card
field
]
(
some->>
(
if
(
=
(
:table_id
card
)
(
:table_id
field
))
[
:field-id
(
:id
field
)]
(
let
[
fk
(
find-fk
(
:table_id
card
)
field
)]
;; Bail out if there are multiple FKs from the same table.
(
when
(
=
(
count
fk
)
1
)
[
:fk->
(
first
fk
)
(
:id
field
)])))
(
some->>
((
:fk-map
field
)
(
:table_id
card
))
(
vector
:dimension
)))
(
defn-
add-filter
...
...
@@ -79,17 +79,21 @@
([
dashboard
]
(
add-filters
dashboard
(
->
dashboard
:orderd_cards
candidates-for-filtering
)))
([
dashboard
dimensions
]
(
reduce
(
fn
[
dashboard
candidate
]
(
let
[
filter-id
(
->
candidate
hash
str
)
dashcards
(
:ordered_cards
dashboard
)
dashcards-new
(
map
#
(
add-filter
%
filter-id
candidate
)
dashcards
)]
(
cond->
dashboard
(
not=
dashcards
dashcards-new
)
(
->
(
assoc
:ordered_cards
dashcards-new
)
(
update
:parameters
conj
{
:id
filter-id
:type
(
filter-type
candidate
)
:name
(
:display_name
candidate
)
:slug
(
:name
candidate
)})))))
dashboard
dimensions
)))
(
->>
dimensions
(
map
#
(
->>
%
(
build-fk-map
(
keep
(
comp
:table_id
:card
)
(
:ordered_cards
dashboard
)))
(
assoc
%
:fk-map
)))
(
reduce
(
fn
[
dashboard
candidate
]
(
let
[
filter-id
(
->
candidate
hash
str
)
dashcards
(
:ordered_cards
dashboard
)
dashcards-new
(
map
#
(
add-filter
%
filter-id
candidate
)
dashcards
)]
(
cond->
dashboard
(
not=
dashcards
dashcards-new
)
(
->
(
assoc
:ordered_cards
dashcards-new
)
(
update
:parameters
conj
{
:id
filter-id
:type
(
filter-type
candidate
)
:name
(
:display_name
candidate
)
:slug
(
:name
candidate
)})))))
dashboard
))))
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