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
0a399fc3
Commit
0a399fc3
authored
7 years ago
by
Sameer Al-Sakran
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #5045 from metabase/fix-e2e-race-conditions
Fix race conditions in e2e tests
parents
491dd11f
006faa00
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/models/query.clj
+26
-9
26 additions, 9 deletions
src/metabase/models/query.clj
with
26 additions
and
9 deletions
src/metabase/models/query.clj
+
26
−
9
View file @
0a399fc3
...
...
@@ -25,17 +25,34 @@
:unsigned
:integer
))
(
defn-
update-rolling-average-execution-time!
"Update the rolling average execution time for query with QUERY-HASH. Returns `true` if a record was updated,
or `false` if no matching records were found."
^
Boolean
[
^
bytes
query-hash,
^
Integer
execution-time-ms
]
(
db/update-where!
Query
{
:query_hash
query-hash
}
:average_execution_time
(
hx/cast
(
int-casting-type
)
(
hx/round
(
hx/+
(
hx/*
0.9
:average_execution_time
)
(
*
0.1
execution-time-ms
))
0
))))
(
defn-
record-new-execution-time!
"Record the execution time for a query with QUERY-HASH that's not already present in the DB.
EXECUTION-TIME-MS is used as a starting point."
[
^
bytes
query-hash,
^
Integer
execution-time-ms
]
(
db/insert!
Query
:query_hash
query-hash
:average_execution_time
execution-time-ms
))
(
defn
update-average-execution-time!
"Update the recorded average execution time for query with QUERY-HASH."
^
Integer
[
^
bytes
query-hash,
^
Integer
execution-time-ms
]
[
^
bytes
query-hash,
^
Integer
execution-time-ms
]
{
:pre
[(
instance?
(
Class/forName
"[B"
)
query-hash
)]}
(
or
;; if there's already a matching Query update the rolling average
(
db/
update-
where!
Query
{
:
query
_
hash
query-hash
}
:average_execution_time
(
hx/cast
(
int-casting-type
)
(
hx/round
(
hx/+
(
hx/*
0.9
:average_execution_
time
)
(
*
0.1
execution-time-ms
))
0
))
)
;; otherwise add a new entry, using the value of EXECUTION-TIME-MS as a starting point
(
db/insert
!
Q
uery
:query_hash
query-hash
:average_execution_time
execution-time-ms
)))
(
update-
rolling-average-execution-time!
query
-
hash
execution-time-ms
)
;; otherwise try adding a new entry. If for some reason there was a race condition and a Query entry was added in the mean
time
;; we'll try updating that existing record
(
try
(
record-new-execution-time!
query-hash
execution-time-ms
)
(
catch
Throwable
e
(
or
(
update-rolling-average-execution-time
!
q
uery
-hash
execution-time-ms
)
;; rethrow e if updating an existing average execution time failed
(
throw
e
)))
)))
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