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
3c4a1ce3
Unverified
Commit
3c4a1ce3
authored
7 months ago
by
Ngoc Khuat
Committed by
GitHub
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove uncessary db calls when updating card (#46480)
parent
741ae589
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/models/card.clj
+36
-37
36 additions, 37 deletions
src/metabase/models/card.clj
test/metabase/models/query_analysis_test.clj
+3
-1
3 additions, 1 deletion
test/metabase/models/query_analysis_test.clj
with
39 additions
and
38 deletions
src/metabase/models/card.clj
+
36
−
37
View file @
3c4a1ce3
...
...
@@ -409,39 +409,40 @@
- card is archived
- card.result_metadata changes and the parameter values source field can't be found anymore"
[{
id
:id,
:as
changes
}]
(
let
[
parameter-cards
(
t2/select
ParameterCard
:card_id
id
)]
(
doseq
[[[
po-type
po-id
]
param-cards
]
(
group-by
(
juxt
:parameterized_object_type
:parameterized_object_id
)
parameter-cards
)]
(
let
[
model
(
case
po-type
:card
'Card
:dashboard
'Dashboard
)
{
:keys
[
parameters
]}
(
t2/select-one
[
model
:parameters
]
:id
po-id
)
affected-param-ids-set
(
cond
;; update all parameters that use this card as source
(
:archived
changes
)
(
set
(
map
:parameter_id
param-cards
))
;; update only parameters that have value_field no longer in this card
(
:result_metadata
changes
)
(
let
[
param-id->parameter
(
m/index-by
:id
parameters
)]
(
->>
param-cards
(
filter
(
fn
[
param-card
]
;; if cant find the value-field in result_metadata, then we should
;; remove it
(
nil?
(
qp.util/field->field-info
(
when
(
some
#
{
:archived
:result_metadata
}
(
keys
changes
))
(
let
[
parameter-cards
(
t2/select
ParameterCard
:card_id
id
)]
(
doseq
[[[
po-type
po-id
]
param-cards
]
(
group-by
(
juxt
:parameterized_object_type
:parameterized_object_id
)
parameter-cards
)]
(
let
[
model
(
case
po-type
:card
'Card
:dashboard
'Dashboard
)
{
:keys
[
parameters
]}
(
t2/select-one
[
model
:parameters
]
:id
po-id
)
affected-param-ids-set
(
cond
;; update all parameters that use this card as source
(
:archived
changes
)
(
set
(
map
:parameter_id
param-cards
))
;; update only parameters that have value_field no longer in this card
(
:result_metadata
changes
)
(
let
[
param-id->parameter
(
m/index-by
:id
parameters
)]
(
->>
param-cards
(
filter
(
fn
[
param-card
]
;; if cant find the value-field in result_metadata, then we should
;; remove it
(
nil?
(
qp.util/field->field-info
(
get-in
(
param-id->parameter
(
:parameter_id
param-card
))
[
:values_source_config
:value_field
])
(
:result_metadata
changes
)))))
(
map
:parameter_id
)
set
))
:else
#
{})
new-parameters
(
map
(
fn
[
parameter
]
(
if
(
affected-param-ids-set
(
:id
parameter
))
(
->
parameter
(
assoc
:values_source_type
nil
)
(
dissoc
:values_source_config
))
parameter
))
parameters
)]
(
when-not
(
=
parameters
new-parameters
)
(
t2/update!
model
po-id
{
:parameters
new-parameters
}))))))
(
map
:parameter_id
)
set
))
:else
#
{})
new-parameters
(
map
(
fn
[
parameter
]
(
if
(
affected-param-ids-set
(
:id
parameter
))
(
->
parameter
(
assoc
:values_source_type
nil
)
(
dissoc
:values_source_config
))
parameter
))
parameters
)]
(
when-not
(
=
parameters
new-parameters
)
(
t2/update!
model
po-id
{
:parameters
new-parameters
}))))))
)
(
defn
model-supports-implicit-actions?
"A model with implicit action supported iff they are a raw table,
...
...
@@ -506,6 +507,10 @@
(
params/assert-valid-parameters
changes
)
(
params/assert-valid-parameter-mappings
changes
)
(
update-parameters-using-card-as-values-source
changes
)
;; TODO: should be done in after-update
;; has to place it here because changes is not available in after-update hook see toucan2#129
(
when
(
contains?
changes
:dataset_query
)
(
query-analysis/analyze-async!
id
))
(
when
(
:parameters
changes
)
(
parameter-card/upsert-or-delete-from-parameters!
"card"
id
(
:parameters
changes
)))
;; additional checks (Enterprise Edition only)
...
...
@@ -558,12 +563,6 @@
maybe-populate-initially-published-at
(
dissoc
:id
)))
(
t2/define-after-update
:model/Card
[
card
]
(
u/prog1
card
(
when
(
contains?
(
t2/changes
card
)
:dataset_query
)
(
query-analysis/analyze-async!
card
))))
;; Cards don't normally get deleted (they get archived instead) so this mostly affects tests
(
t2/define-before-delete
:model/Card
[{
:keys
[
id
]
:as
_card
}]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/models/query_analysis_test.clj
+
3
−
1
View file @
3c4a1ce3
...
...
@@ -59,7 +59,9 @@
[
card-id
query
]
(
if
(
string?
query
)
(
t2/update!
:model/Card
card-id
{
:dataset_query
(
mt/native-query
{
:query
query
})})
(
t2/update!
:model/Card
card-id
{
:dataset_query
query
})))
(
t2/update!
:model/Card
card-id
{
:dataset_query
query
}))
;; TODO remove this hack, adjusting the queue design to handle unsaved cards #45460
(
query-analysis/analyze-card!
card-id
))
;;;;
;;;; Actual tests
...
...
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