Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
0f6ebf39
Commit
0f6ebf39
authored
4 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Better type annotations for simple_upsert_txn
most of these params don't really need to be lists.
parent
b2dba060
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/database.py
+43
-30
43 additions, 30 deletions
synapse/storage/database.py
with
43 additions
and
30 deletions
synapse/storage/database.py
+
43
−
30
View file @
0f6ebf39
...
...
@@ -49,6 +49,7 @@ from synapse.metrics.background_process_metrics import run_as_background_process
from
synapse.storage.background_updates
import
BackgroundUpdater
from
synapse.storage.engines
import
BaseDatabaseEngine
,
PostgresEngine
,
Sqlite3Engine
from
synapse.storage.types
import
Connection
,
Cursor
from
synapse.types
import
Collection
from
synapse.util.stringutils
import
exception_to_unicode
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -889,20 +890,24 @@ class Database(object):
txn
.
execute
(
sql
,
list
(
allvalues
.
values
()))
def
simple_upsert_many_txn
(
self
,
txn
,
table
,
key_names
,
key_values
,
value_names
,
value_values
):
self
,
txn
:
LoggingTransaction
,
table
:
str
,
key_names
:
Collection
[
str
],
key_values
:
Collection
[
Iterable
[
Any
]],
value_names
:
Collection
[
str
],
value_values
:
Iterable
[
Iterable
[
str
]],
)
->
None
:
"""
Upsert, many times.
Args:
table (str): The table to upsert into
key_names (list[str]): The key column names.
key_values (list[list]): A list of each row
'
s key column values.
value_names (list[str]): The value column names. If empty, no
values will be used, even if value_values is provided.
value_values (list[list]): A list of each row
'
s value column values.
Returns:
None
table: The table to upsert into
key_names: The key column names.
key_values: A list of each row
'
s key column values.
value_names: The value column names
value_values: A list of each row
'
s value column values.
Ignored if value_names is empty.
"""
if
self
.
engine
.
can_native_upsert
and
table
not
in
self
.
_unsafe_to_upsert_tables
:
return
self
.
simple_upsert_many_txn_native_upsert
(
...
...
@@ -914,20 +919,24 @@ class Database(object):
)
def
simple_upsert_many_txn_emulated
(
self
,
txn
,
table
,
key_names
,
key_values
,
value_names
,
value_values
):
self
,
txn
:
LoggingTransaction
,
table
:
str
,
key_names
:
Iterable
[
str
],
key_values
:
Collection
[
Iterable
[
Any
]],
value_names
:
Collection
[
str
],
value_values
:
Iterable
[
Iterable
[
str
]],
)
->
None
:
"""
Upsert, many times, but without native UPSERT support or batching.
Args:
table (str): The table to upsert into
key_names (list[str]): The key column names.
key_values (list[list]): A list of each row
'
s key column values.
value_names (list[str]): The value column names. If empty, no
values will be used, even if value_values is provided.
value_values (list[list]): A list of each row
'
s value column values.
Returns:
None
table: The table to upsert into
key_names: The key column names.
key_values: A list of each row
'
s key column values.
value_names: The value column names
value_values: A list of each row
'
s value column values.
Ignored if value_names is empty.
"""
# No value columns, therefore make a blank list so that the following
# zip() works correctly.
...
...
@@ -941,20 +950,24 @@ class Database(object):
self
.
simple_upsert_txn_emulated
(
txn
,
table
,
_keys
,
_vals
)
def
simple_upsert_many_txn_native_upsert
(
self
,
txn
,
table
,
key_names
,
key_values
,
value_names
,
value_values
):
self
,
txn
:
LoggingTransaction
,
table
:
str
,
key_names
:
Collection
[
str
],
key_values
:
Collection
[
Iterable
[
Any
]],
value_names
:
Collection
[
str
],
value_values
:
Iterable
[
Iterable
[
Any
]],
)
->
None
:
"""
Upsert, many times, using batching where possible.
Args:
table (str): The table to upsert into
key_names (list[str]): The key column names.
key_values (list[list]): A list of each row
'
s key column values.
value_names (list[str]): The value column names. If empty, no
values will be used, even if value_values is provided.
value_values (list[list]): A list of each row
'
s value column values.
Returns:
None
table: The table to upsert into
key_names: The key column names.
key_values: A list of each row
'
s key column values.
value_names: The value column names
value_values: A list of each row
'
s value column values.
Ignored if value_names is empty.
"""
allnames
=
[]
# type: List[str]
allnames
.
extend
(
key_names
)
...
...
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