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
Package registry
Container Registry
Model registry
Operate
Terraform modules
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
Timo Ley
synapse
Commits
09fd0eda
Unverified
Commit
09fd0eda
authored
4 years ago
by
Richard van der Hoff
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Micro-optimisations to get_auth_chain_ids (#8132)
parent
3f91638d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/8132.misc
+1
-0
1 addition, 0 deletions
changelog.d/8132.misc
synapse/storage/databases/main/event_federation.py
+17
-23
17 additions, 23 deletions
synapse/storage/databases/main/event_federation.py
with
18 additions
and
23 deletions
changelog.d/8132.misc
0 → 100644
+
1
−
0
View file @
09fd0eda
Micro-optimisations to get_auth_chain_ids.
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/event_federation.py
+
17
−
23
View file @
09fd0eda
...
...
@@ -15,14 +15,16 @@
import
itertools
import
logging
from
queue
import
Empty
,
PriorityQueue
from
typing
import
Dict
,
Iterable
,
List
,
Optional
,
Set
,
Tuple
from
typing
import
Dict
,
Iterable
,
List
,
Set
,
Tuple
from
synapse.api.errors
import
StoreError
from
synapse.events
import
EventBase
from
synapse.metrics.background_process_metrics
import
run_as_background_process
from
synapse.storage._base
import
SQLBaseStore
,
make_in_list_sql_clause
from
synapse.storage.database
import
DatabasePool
from
synapse.storage.database
import
DatabasePool
,
LoggingTransaction
from
synapse.storage.databases.main.events_worker
import
EventsWorkerStore
from
synapse.storage.databases.main.signatures
import
SignatureWorkerStore
from
synapse.types
import
Collection
from
synapse.util.caches.descriptors
import
cached
from
synapse.util.iterutils
import
batch_iter
...
...
@@ -30,12 +32,14 @@ logger = logging.getLogger(__name__)
class
EventFederationWorkerStore
(
EventsWorkerStore
,
SignatureWorkerStore
,
SQLBaseStore
):
async
def
get_auth_chain
(
self
,
event_ids
,
include_given
=
False
):
async
def
get_auth_chain
(
self
,
event_ids
:
Collection
[
str
],
include_given
:
bool
=
False
)
->
List
[
EventBase
]:
"""
Get auth events for given event_ids. The events *must* be state events.
Args:
event_ids
(list)
: state events
include_given
(bool)
: include the given events in result
event_ids: state events
include_given: include the given events in result
Returns:
list of events
...
...
@@ -45,43 +49,34 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas
)
return
await
self
.
get_events_as_list
(
event_ids
)
def
get_auth_chain_ids
(
self
,
event_ids
:
List
[
str
],
include_given
:
bool
=
False
,
ignore_events
:
Optional
[
Set
[
str
]]
=
None
,
):
async
def
get_auth_chain_ids
(
self
,
event_ids
:
Collection
[
str
],
include_given
:
bool
=
False
,
)
->
List
[
str
]:
"""
Get auth events for given event_ids. The events *must* be state events.
Args:
event_ids: state events
include_given: include the given events in result
ignore_events: Set of events to exclude from the returned auth
chain. This is useful if the caller will just discard the
given events anyway, and saves us from figuring out their auth
chains if not required.
Returns:
list of event_ids
"""
return
self
.
db_pool
.
runInteraction
(
return
await
self
.
db_pool
.
runInteraction
(
"
get_auth_chain_ids
"
,
self
.
_get_auth_chain_ids_txn
,
event_ids
,
include_given
,
ignore_events
,
)
def
_get_auth_chain_ids_txn
(
self
,
txn
,
event_ids
,
include_given
,
ignore_events
):
if
ignore_events
is
None
:
ignore_events
=
set
()
def
_get_auth_chain_ids_txn
(
self
,
txn
:
LoggingTransaction
,
event_ids
:
Collection
[
str
],
include_given
:
bool
)
->
List
[
str
]:
if
include_given
:
results
=
set
(
event_ids
)
else
:
results
=
set
()
base_sql
=
"
SELECT auth_id FROM event_auth WHERE
"
base_sql
=
"
SELECT
DISTINCT
auth_id FROM event_auth WHERE
"
front
=
set
(
event_ids
)
while
front
:
...
...
@@ -93,7 +88,6 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas
txn
.
execute
(
base_sql
+
clause
,
args
)
new_front
.
update
(
r
[
0
]
for
r
in
txn
)
new_front
-=
ignore_events
new_front
-=
results
front
=
new_front
...
...
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