Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
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
TeDomum
Matrix
Commits
912e0249
Unverified
Commit
912e0249
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convert runInteraction to async/await (#8156)
parent
112266ea
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
changelog.d/8156.misc
+1
-0
1 addition, 0 deletions
changelog.d/8156.misc
synapse/storage/database.py
+14
-15
14 additions, 15 deletions
synapse/storage/database.py
with
15 additions
and
15 deletions
changelog.d/8156.misc
0 → 100644
+
1
−
0
View file @
912e0249
Convert various parts of the codebase to async/await.
This diff is collapsed.
Click to expand it.
synapse/storage/database.py
+
14
−
15
View file @
912e0249
...
...
@@ -28,6 +28,7 @@ from typing import (
Optional
,
Tuple
,
TypeVar
,
cast
,
overload
,
)
...
...
@@ -35,7 +36,6 @@ from prometheus_client import Histogram
from
typing_extensions
import
Literal
from
twisted.enterprise
import
adbapi
from
twisted.internet
import
defer
from
synapse.api.errors
import
StoreError
from
synapse.config.database
import
DatabaseConnectionConfig
...
...
@@ -507,8 +507,9 @@ class DatabasePool(object):
self
.
_txn_perf_counters
.
update
(
desc
,
duration
)
sql_txn_timer
.
labels
(
desc
).
observe
(
duration
)
@defer.inlineCallbacks
def
runInteraction
(
self
,
desc
:
str
,
func
:
Callable
,
*
args
:
Any
,
**
kwargs
:
Any
):
async
def
runInteraction
(
self
,
desc
:
str
,
func
:
"
Callable[..., R]
"
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
R
:
"""
Starts a transaction on the database and runs a given function
Arguments:
...
...
@@ -521,7 +522,7 @@ class DatabasePool(object):
kwargs: named args to pass to `func`
Returns:
Deferred:
The result of func
The result of func
"""
after_callbacks
=
[]
# type: List[_CallbackListEntry]
exception_callbacks
=
[]
# type: List[_CallbackListEntry]
...
...
@@ -530,16 +531,14 @@ class DatabasePool(object):
logger
.
warning
(
"
Starting db txn
'
%s
'
from sentinel context
"
,
desc
)
try
:
result
=
yield
defer
.
ensureDeferred
(
self
.
runWithConnection
(
self
.
new_transaction
,
desc
,
after_callbacks
,
exception_callbacks
,
func
,
*
args
,
**
kwargs
)
result
=
await
self
.
runWithConnection
(
self
.
new_transaction
,
desc
,
after_callbacks
,
exception_callbacks
,
func
,
*
args
,
**
kwargs
)
for
after_callback
,
after_args
,
after_kwargs
in
after_callbacks
:
...
...
@@ -549,7 +548,7 @@ class DatabasePool(object):
after_callback
(
*
after_args
,
**
after_kwargs
)
raise
return
result
return
cast
(
R
,
result
)
async
def
runWithConnection
(
self
,
func
:
"
Callable[..., R]
"
,
*
args
:
Any
,
**
kwargs
:
Any
...
...
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