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
4624d603
Commit
4624d603
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Docs
parent
5989637f
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
synapse/handlers/receipts.py
+8
-3
8 additions, 3 deletions
synapse/handlers/receipts.py
synapse/storage/receipts.py
+28
-3
28 additions, 3 deletions
synapse/storage/receipts.py
with
36 additions
and
6 deletions
synapse/handlers/receipts.py
+
8
−
3
View file @
4624d603
...
...
@@ -149,7 +149,8 @@ class ReceiptsHandler(BaseHandler):
"""
Gets all receipts for a room, upto the given key.
"""
result
=
yield
self
.
store
.
get_linearized_receipts_for_room
(
room_id
,
None
,
to_key
room_id
,
to_key
=
to_key
,
)
if
not
result
:
...
...
@@ -176,7 +177,9 @@ class ReceiptEventSource(object):
rooms
=
yield
self
.
store
.
get_rooms_for_user
(
user
.
to_string
())
rooms
=
[
room
.
room_id
for
room
in
rooms
]
events
=
yield
self
.
store
.
get_linearized_receipts_for_rooms
(
rooms
,
from_key
,
to_key
rooms
,
from_key
=
from_key
,
to_key
=
to_key
,
)
defer
.
returnValue
((
events
,
to_key
))
...
...
@@ -196,7 +199,9 @@ class ReceiptEventSource(object):
rooms
=
yield
self
.
store
.
get_rooms_for_user
(
user
.
to_string
())
rooms
=
[
room
.
room_id
for
room
in
rooms
]
events
=
yield
self
.
store
.
get_linearized_receipts_for_rooms
(
rooms
,
from_key
,
to_key
rooms
,
from_key
=
from_key
,
to_key
=
to_key
,
)
defer
.
returnValue
((
events
,
to_key
))
This diff is collapsed.
Click to expand it.
synapse/storage/receipts.py
+
28
−
3
View file @
4624d603
...
...
@@ -34,8 +34,17 @@ class ReceiptsStore(SQLBaseStore):
self
.
_receipts_stream_cache
=
_RoomStreamChangeCache
()
@defer.inlineCallbacks
def
get_linearized_receipts_for_rooms
(
self
,
room_ids
,
from
_key
,
to_key
):
def
get_linearized_receipts_for_rooms
(
self
,
room_ids
,
to
_key
,
from_key
=
None
):
"""
Get receipts for multiple rooms for sending to clients.
Args:
room_ids (list): List of room_ids.
to_key (int): Max stream id to fetch receipts upto.
from_key (int): Min stream id to fetch receipts from. None fetches
from the start.
Returns:
list: A list of receipts.
"""
room_ids
=
set
(
room_ids
)
...
...
@@ -46,7 +55,9 @@ class ReceiptsStore(SQLBaseStore):
results
=
yield
defer
.
gatherResults
(
[
self
.
get_linearized_receipts_for_room
(
room_id
,
from_key
,
to_key
)
self
.
get_linearized_receipts_for_room
(
room_id
,
to_key
,
from_key
=
from_key
)
for
room_id
in
room_ids
],
consumeErrors
=
True
,
...
...
@@ -55,8 +66,17 @@ class ReceiptsStore(SQLBaseStore):
defer
.
returnValue
([
ev
for
res
in
results
for
ev
in
res
])
@defer.inlineCallbacks
def
get_linearized_receipts_for_room
(
self
,
room_id
,
from
_key
,
to_key
):
def
get_linearized_receipts_for_room
(
self
,
room_id
,
to
_key
,
from_key
=
None
):
"""
Get receipts for a single room for sending to clients.
Args:
room_ids (str): The room id.
to_key (int): Max stream id to fetch receipts upto.
from_key (int): Min stream id to fetch receipts from. None fetches
from the start.
Returns:
list: A list of receipts.
"""
def
f
(
txn
):
if
from_key
:
...
...
@@ -288,6 +308,9 @@ class _RoomStreamChangeCache(object):
@defer.inlineCallbacks
def
get_rooms_changed
(
self
,
store
,
room_ids
,
key
):
"""
Returns subset of room ids that have had new receipts since the
given key. If the key is too old it will just return the given list.
"""
if
key
>
(
yield
self
.
_get_earliest_key
(
store
)):
keys
=
self
.
_cache
.
keys
()
i
=
keys
.
bisect_right
(
key
)
...
...
@@ -302,6 +325,8 @@ class _RoomStreamChangeCache(object):
@defer.inlineCallbacks
def
room_has_changed
(
self
,
store
,
room_id
,
key
):
"""
Informs the cache that the room has been changed at the given key.
"""
if
key
>
(
yield
self
.
_get_earliest_key
(
store
)):
old_key
=
self
.
_room_to_key
.
get
(
room_id
,
None
)
if
old_key
:
...
...
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