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
0cd01f5c
Commit
0cd01f5c
authored
8 years ago
by
Erik Johnston
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2108 from matrix-org/erikj/current_state_ids
Speed up get_current_state_ids
parents
54f59bd7
2a3e822f
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/state.py
+26
-10
26 additions, 10 deletions
synapse/storage/state.py
with
26 additions
and
10 deletions
synapse/storage/state.py
+
26
−
10
View file @
0cd01f5c
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
# limitations under the License.
# limitations under the License.
from
._base
import
SQLBaseStore
from
._base
import
SQLBaseStore
from
synapse.util.caches.descriptors
import
cached
,
cachedList
,
cachedInlineCallbacks
from
synapse.util.caches.descriptors
import
cached
,
cachedList
from
synapse.util.caches
import
intern_string
from
synapse.util.caches
import
intern_string
from
synapse.storage.engines
import
PostgresEngine
from
synapse.storage.engines
import
PostgresEngine
...
@@ -69,17 +69,33 @@ class StateStore(SQLBaseStore):
...
@@ -69,17 +69,33 @@ class StateStore(SQLBaseStore):
where_clause
=
"
type=
'
m.room.member
'"
,
where_clause
=
"
type=
'
m.room.member
'"
,
)
)
@cached
InlineCallbacks
(
max_entries
=
100000
,
iterable
=
True
)
@cached
(
max_entries
=
100000
,
iterable
=
True
)
def
get_current_state_ids
(
self
,
room_id
):
def
get_current_state_ids
(
self
,
room_id
):
rows
=
yield
self
.
_simple_select_list
(
"""
Get the current state event ids for a room based on the
table
=
"
current_state_events
"
,
current_state_events table.
keyvalues
=
{
"
room_id
"
:
room_id
},
retcols
=
[
"
event_id
"
,
"
type
"
,
"
state_key
"
],
Args:
desc
=
"
_calculate_state_delta
"
,
room_id (str)
Returns:
deferred: dict of (type, state_key) -> event_id
"""
def
_get_current_state_ids_txn
(
txn
):
txn
.
execute
(
"""
SELECT type, state_key, event_id FROM current_state_events
WHERE room_id = ?
"""
,
(
room_id
,)
)
return
{
(
r
[
0
],
r
[
1
]):
r
[
2
]
for
r
in
txn
}
return
self
.
runInteraction
(
"
get_current_state_ids
"
,
_get_current_state_ids_txn
,
)
)
defer
.
returnValue
({
(
r
[
"
type
"
],
r
[
"
state_key
"
]):
r
[
"
event_id
"
]
for
r
in
rows
})
@defer.inlineCallbacks
@defer.inlineCallbacks
def
get_state_groups_ids
(
self
,
room_id
,
event_ids
):
def
get_state_groups_ids
(
self
,
room_id
,
event_ids
):
...
...
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