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
73880268
Commit
73880268
authored
8 years ago
by
Luke Barnard
Browse files
Options
Downloads
Patches
Plain Diff
Refactor event ordering check to events store
parent
131485ef
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/read_marker.py
+4
-28
4 additions, 28 deletions
synapse/handlers/read_marker.py
synapse/storage/events.py
+28
-0
28 additions, 0 deletions
synapse/storage/events.py
with
32 additions
and
28 deletions
synapse/handlers/read_marker.py
+
4
−
28
View file @
73880268
...
...
@@ -42,41 +42,17 @@ class ReadMarkerHandler(BaseHandler):
"""
# Get ordering for existing read marker
with
(
yield
self
.
read_marker_linearizer
.
queue
(
room_id
+
"
_
"
+
user_id
)):
with
(
yield
self
.
read_marker_linearizer
.
queue
(
(
room_id
,
user_id
))
)
:
account_data
=
yield
self
.
store
.
get_account_data_for_room
(
user_id
,
room_id
)
existing_read_marker
=
account_data
[
"
m.read_marker
"
]
should_update
=
True
res
=
yield
self
.
store
.
_simple_select_one
(
table
=
"
events
"
,
retcols
=
[
"
topological_ordering
"
,
"
stream_ordering
"
],
keyvalues
=
{
"
event_id
"
:
event_id
},
allow_none
=
True
)
if
not
res
:
raise
SynapseError
(
404
,
'
Event does not exist
'
)
if
existing_read_marker
:
new_to
=
int
(
res
[
"
topological_ordering
"
])
new_so
=
int
(
res
[
"
stream_ordering
"
])
# Get ordering for existing read marker
res
=
yield
self
.
store
.
_simple_select_one
(
table
=
"
events
"
,
retcols
=
[
"
topological_ordering
"
,
"
stream_ordering
"
],
keyvalues
=
{
"
event_id
"
:
existing_read_marker
[
'
marker
'
]},
allow_none
=
True
should_update
=
yield
self
.
store
.
is_event_after
(
existing_read_marker
[
'
marker
'
],
event_id
)
existing_to
=
int
(
res
[
"
topological_ordering
"
])
if
res
else
None
existing_so
=
int
(
res
[
"
stream_ordering
"
])
if
res
else
None
# Prevent updating if the existing marker is ahead in the stream
if
existing_to
>
new_to
:
should_update
=
False
elif
existing_to
==
new_to
and
existing_so
>=
new_so
:
should_update
=
False
if
should_update
:
content
=
{
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/events.py
+
28
−
0
View file @
73880268
...
...
@@ -2159,6 +2159,34 @@ class EventsStore(SQLBaseStore):
]
)
@defer.inlineCallbacks
def
is_event_after
(
self
,
event_id1
,
event_id2
):
is_after
=
True
to_1
,
so_1
=
yield
self
.
_get_event_ordering
(
event_id1
)
to_2
,
so_2
=
yield
self
.
_get_event_ordering
(
event_id2
)
# Prevent updating if the existing marker is ahead in the stream
if
to_1
>
to_2
:
is_after
=
False
elif
to_1
==
to_2
and
so_1
>=
so_2
:
is_after
=
False
defer
.
returnValue
(
is_after
)
@defer.inlineCallbacks
def
_get_event_ordering
(
self
,
event_id
):
res
=
yield
self
.
_simple_select_one
(
table
=
"
events
"
,
retcols
=
[
"
topological_ordering
"
,
"
stream_ordering
"
],
keyvalues
=
{
"
event_id
"
:
event_id
},
allow_none
=
True
)
if
not
res
:
raise
SynapseError
(
404
,
"
Could not find event %s
"
%
(
event_id
,))
defer
.
returnValue
((
int
(
res
[
"
topological_ordering
"
]),
int
(
res
[
"
stream_ordering
"
])))
AllNewEventsResult
=
namedtuple
(
"
AllNewEventsResult
"
,
[
"
new_forward_events
"
,
"
new_backfill_events
"
,
...
...
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