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
c486fa5f
Unverified
Commit
c486fa5f
authored
3 years ago
by
Patrick Cloke
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add some missing type hints to cache datastore. (#12216)
parent
86965605
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/12216.misc
+1
-0
1 addition, 0 deletions
changelog.d/12216.misc
synapse/storage/databases/main/cache.py
+36
-21
36 additions, 21 deletions
synapse/storage/databases/main/cache.py
with
37 additions
and
21 deletions
changelog.d/12216.misc
0 → 100644
+
1
−
0
View file @
c486fa5f
Add missing type hints for cache storage.
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/cache.py
+
36
−
21
View file @
c486fa5f
...
...
@@ -23,6 +23,7 @@ from synapse.replication.tcp.streams.events import (
EventsStream
,
EventsStreamCurrentStateRow
,
EventsStreamEventRow
,
EventsStreamRow
,
)
from
synapse.storage._base
import
SQLBaseStore
from
synapse.storage.database
import
(
...
...
@@ -31,6 +32,7 @@ from synapse.storage.database import (
LoggingTransaction
,
)
from
synapse.storage.engines
import
PostgresEngine
from
synapse.util.caches.descriptors
import
_CachedFunction
from
synapse.util.iterutils
import
batch_iter
if
TYPE_CHECKING
:
...
...
@@ -82,7 +84,9 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
if
last_id
==
current_id
:
return
[],
current_id
,
False
def
get_all_updated_caches_txn
(
txn
):
def
get_all_updated_caches_txn
(
txn
:
LoggingTransaction
,
)
->
Tuple
[
List
[
Tuple
[
int
,
tuple
]],
int
,
bool
]:
# We purposefully don't bound by the current token, as we want to
# send across cache invalidations as quickly as possible. Cache
# invalidations are idempotent, so duplicates are fine.
...
...
@@ -107,7 +111,9 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
"
get_all_updated_caches
"
,
get_all_updated_caches_txn
)
def
process_replication_rows
(
self
,
stream_name
,
instance_name
,
token
,
rows
):
def
process_replication_rows
(
self
,
stream_name
:
str
,
instance_name
:
str
,
token
:
int
,
rows
:
Iterable
[
Any
]
)
->
None
:
if
stream_name
==
EventsStream
.
NAME
:
for
row
in
rows
:
self
.
_process_event_stream_row
(
token
,
row
)
...
...
@@ -142,10 +148,11 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
super
().
process_replication_rows
(
stream_name
,
instance_name
,
token
,
rows
)
def
_process_event_stream_row
(
self
,
token
,
row
)
:
def
_process_event_stream_row
(
self
,
token
:
int
,
row
:
EventsStreamRow
)
->
None
:
data
=
row
.
data
if
row
.
type
==
EventsStreamEventRow
.
TypeId
:
assert
isinstance
(
data
,
EventsStreamEventRow
)
self
.
_invalidate_caches_for_event
(
token
,
data
.
event_id
,
...
...
@@ -157,9 +164,8 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
backfilled
=
False
,
)
elif
row
.
type
==
EventsStreamCurrentStateRow
.
TypeId
:
self
.
_curr_state_delta_stream_cache
.
entity_has_changed
(
row
.
data
.
room_id
,
token
)
assert
isinstance
(
data
,
EventsStreamCurrentStateRow
)
self
.
_curr_state_delta_stream_cache
.
entity_has_changed
(
data
.
room_id
,
token
)
if
data
.
type
==
EventTypes
.
Member
:
self
.
get_rooms_for_user_with_stream_ordering
.
invalidate
(
...
...
@@ -170,15 +176,15 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
def
_invalidate_caches_for_event
(
self
,
stream_ordering
,
event_id
,
room_id
,
etype
,
state_key
,
redacts
,
relates_to
,
backfilled
,
):
stream_ordering
:
int
,
event_id
:
str
,
room_id
:
str
,
etype
:
str
,
state_key
:
Optional
[
str
]
,
redacts
:
Optional
[
str
]
,
relates_to
:
Optional
[
str
]
,
backfilled
:
bool
,
)
->
None
:
self
.
_invalidate_get_event_cache
(
event_id
)
self
.
have_seen_event
.
invalidate
((
room_id
,
event_id
))
...
...
@@ -207,7 +213,9 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
self
.
get_thread_summary
.
invalidate
((
relates_to
,))
self
.
get_thread_participated
.
invalidate
((
relates_to
,))
async
def
invalidate_cache_and_stream
(
self
,
cache_name
:
str
,
keys
:
Tuple
[
Any
,
...]):
async
def
invalidate_cache_and_stream
(
self
,
cache_name
:
str
,
keys
:
Tuple
[
Any
,
...]
)
->
None
:
"""
Invalidates the cache and adds it to the cache stream so slaves
will know to invalidate their caches.
...
...
@@ -227,7 +235,12 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
keys
,
)
def
_invalidate_cache_and_stream
(
self
,
txn
,
cache_func
,
keys
):
def
_invalidate_cache_and_stream
(
self
,
txn
:
LoggingTransaction
,
cache_func
:
_CachedFunction
,
keys
:
Tuple
[
Any
,
...],
)
->
None
:
"""
Invalidates the cache and adds it to the cache stream so slaves
will know to invalidate their caches.
...
...
@@ -238,7 +251,9 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
txn
.
call_after
(
cache_func
.
invalidate
,
keys
)
self
.
_send_invalidation_to_replication
(
txn
,
cache_func
.
__name__
,
keys
)
def
_invalidate_all_cache_and_stream
(
self
,
txn
,
cache_func
):
def
_invalidate_all_cache_and_stream
(
self
,
txn
:
LoggingTransaction
,
cache_func
:
_CachedFunction
)
->
None
:
"""
Invalidates the entire cache and adds it to the cache stream so slaves
will know to invalidate their caches.
"""
...
...
@@ -279,8 +294,8 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
)
def
_send_invalidation_to_replication
(
self
,
txn
,
cache_name
:
str
,
keys
:
Optional
[
Iterable
[
Any
]]
):
self
,
txn
:
LoggingTransaction
,
cache_name
:
str
,
keys
:
Optional
[
Iterable
[
Any
]]
)
->
None
:
"""
Notifies replication that given cache has been invalidated.
Note that this does *not* invalidate the cache locally.
...
...
@@ -315,7 +330,7 @@ class CacheInvalidationWorkerStore(SQLBaseStore):
"
instance_name
"
:
self
.
_instance_name
,
"
cache_func
"
:
cache_name
,
"
keys
"
:
keys
,
"
invalidation_ts
"
:
self
.
clock
.
time_msec
(),
"
invalidation_ts
"
:
self
.
_
clock
.
time_msec
(),
},
)
...
...
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