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
7eb7cd30
Unverified
Commit
7eb7cd30
authored
1 year ago
by
Chris Truter
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Various readability improvements around based_on_upload (#38507)
Co-authored-by:
Callum Herries
<
calherries@gmail.com
>
parent
425d570c
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/api/collection.clj
+5
-7
5 additions, 7 deletions
src/metabase/api/collection.clj
src/metabase/upload.clj
+23
-26
23 additions, 26 deletions
src/metabase/upload.clj
with
28 additions
and
33 deletions
src/metabase/api/collection.clj
+
5
−
7
View file @
7eb7cd30
...
...
@@ -406,14 +406,12 @@
(
defmethod
post-process-collection-children
:dataset
[
_
rows
]
(
let
[
dataset_
queries
(
map
:dataset_query
rows
)
]
(
->>
rows
;;
normalize dataset queries
just for based_on_upload hydration
(
map
#
(
update
%
:dataset_query
(
comp
mbql.normalize/normalize
json/parse-string
))
)
(
let
[
queries
-before
(
map
:dataset_query
rows
)
queries-parsed
(
map
(
comp
mbql.normalize/normalize
json/parse-string
)
queries-before
)]
;; We need to
normalize
the
dataset queries
for hydration, but reset the field to avoid leaking that transform.
(
->>
(
map
#
(
assoc
%
2
:dataset_query
%1
)
queries-parsed
rows
)
upload/model-hydrate-based-on-upload
(
map
(
fn
[
dataset_query
row
]
(
assoc
row
:dataset_query
dataset_query
))
dataset_queries
)
(
map
#
(
assoc
%2
:dataset_query
%1
)
queries-before
)
(
post-process-collection-children
:card
))))
(
defmethod
collection-children-query
:card
...
...
This diff is collapsed.
Click to expand it.
src/metabase/upload.clj
+
23
−
26
View file @
7eb7cd30
...
...
@@ -709,13 +709,10 @@
(
defn
uploadable-table-ids
"Returns the subset of table ids where the user can upload to the table."
[
table-ids
]
(
if
(
empty?
table-ids
)
#
{}
(
let
[
tables
(
t2/hydrate
(
t2/select
:model/Table
:id
[
:in
table-ids
])
:db
)]
(
set
(
keep
(
fn
[
t
]
(
when
(
can-upload-to-table?
(
:db
t
)
t
)
(
:id
t
)))
tables
)))))
(
set
(
when
(
seq
table-ids
)
(
->>
(
t2/hydrate
(
t2/select
:model/Table
:id
[
:in
table-ids
])
:db
)
(
filter
#
(
can-upload-to-table?
(
:db
%
)
%
))
(
map
:id
)))))
(
defn-
no-joins?
"Returns true if `query` has no joins in it, otherwise false."
...
...
@@ -735,23 +732,22 @@
[
:table_id
[
:maybe
ms/PositiveInt
]]
;; is_upload can be provided for an optional optimization
[
:is_upload
{
:optional
true
}
[
:maybe
:boolean
]]]]]
(
let
[
table-ids
(
->>
models
;; as an optimization when listing collection items (GET /api/collection/items),
;; we might already know that the table is not an upload if is_upload=false. We
;; can skip making more queries if so
(
remove
#
(
false?
(
:is_upload
%
)))
(
keep
:table_id
)
set
)
uploadable-table-ids
(
set
(
uploadable-table-ids
table-ids
))
based-on-upload
(
fn
[
model
]
(
when-let
[
dataset_query
(
:dataset_query
model
)]
; dataset_query is sometimes null in tests
(
let
[
query
(
lib/->pMBQL
dataset_query
)]
(
when
(
and
(
some->
model
:query_type
name
(
=
"query"
))
(
contains?
uploadable-table-ids
(
:table_id
model
))
(
no-joins?
query
))
(
lib/source-table-id
query
)))))]
(
map
#
(
m/assoc-some
%
:based_on_upload
(
based-on-upload
%
))
models
)))
(
let
[
table-ids
(
->>
models
;; as an optimization when listing collection items (GET /api/collection/items),
;; we might already know that the table is not an upload if is_upload=false. We
;; can skip making more queries if so
(
remove
#
(
false?
(
:is_upload
%
)))
(
keep
:table_id
)
set
)
mbql?
(
fn
[
model
]
(
=
"query"
(
name
(
:query_type
model
"query"
))))
has-uploadable-table?
(
comp
(
uploadable-table-ids
table-ids
)
:table_id
)]
(
for
[
model
models
]
(
m/assoc-some
model
:based_on_upload
(
when-let
[
query
(
some->
model
:dataset_query
lib/->pMBQL
not-empty
)]
; dataset_query can be empty in tests
(
when
(
and
(
mbql?
model
)
(
has-uploadable-table?
model
)
(
no-joins?
query
))
(
lib/source-table-id
query
)))))))
(
mi/define-batched-hydration-method
based-on-upload
:based_on_upload
...
...
@@ -763,5 +759,6 @@
- uploads are enabled
Otherwise based_on_upload is nil."
[
cards
]
(
let
[
models-by-id
(
m/index-by
:id
(
model-hydrate-based-on-upload
(
filter
:dataset
cards
)))]
(
map
#
(
or
(
models-by-id
(
:id
%
))
%
)
cards
)))
(
let
[
id->model
(
m/index-by
:id
(
model-hydrate-based-on-upload
(
filter
:dataset
cards
)))
card->maybe-model
(
comp
id->model
:id
)]
(
map
#
(
or
(
card->maybe-model
%
)
%
)
cards
)))
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