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
85c0999b
Commit
85c0999b
authored
4 years ago
by
Jason Robinson
Browse files
Options
Downloads
Patches
Plain Diff
Add Rooms admin forward extremities DELETE endpoint
Signed-off-by:
Jason Robinson
<
jasonr@matrix.org
>
parent
c91045f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/rest/admin/rooms.py
+5
-0
5 additions, 0 deletions
synapse/rest/admin/rooms.py
synapse/storage/databases/main/events_forward_extremities.py
+48
-1
48 additions, 1 deletion
synapse/storage/databases/main/events_forward_extremities.py
with
53 additions
and
1 deletion
synapse/rest/admin/rooms.py
+
5
−
0
View file @
85c0999b
...
...
@@ -543,6 +543,11 @@ class ForwardExtremitiesRestServlet(RestServlet):
room_id
=
await
self
.
resolve_room_id
(
room_identifier
)
deleted_count
=
await
self
.
store
.
delete_forward_extremities_for_room
(
room_id
)
return
200
,
{
"
deleted
"
:
deleted_count
,
}
async
def
on_GET
(
self
,
request
,
room_identifier
):
requester
=
await
self
.
auth
.
get_user_by_req
(
request
)
await
assert_user_is_admin
(
self
.
auth
,
requester
.
user
)
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/events_forward_extremities.py
+
48
−
1
View file @
85c0999b
...
...
@@ -4,7 +4,54 @@ from synapse.storage._base import SQLBaseStore
class
EventForwardExtremitiesStore
(
SQLBaseStore
):
async
def
delete_forward_extremities_for_room
(
self
,
room_id
:
str
)
->
int
:
"""
Delete any extra forward extremities for a room.
Returns count deleted.
"""
def
delete_forward_extremities_for_room_txn
(
txn
):
# First we need to get the event_id to not delete
sql
=
(
"
SELECT
"
"
last_value(event_id) OVER w AS event_id
"
"
FROM event_forward_extremities
"
"
NATURAL JOIN events
"
"
where room_id = ?
"
"
WINDOW w AS (
"
"
PARTITION BY room_id
"
"
ORDER BY stream_ordering
"
"
range between unbounded preceding and unbounded following
"
"
)
"
"
ORDER BY stream_ordering
"
)
txn
.
execute
(
sql
,
(
room_id
,))
rows
=
txn
.
fetchall
()
# TODO: should this raise a SynapseError instead of better to blow?
event_id
=
rows
[
0
][
0
]
# Now delete the extra forward extremities
sql
=
(
"
DELETE FROM event_forward_extremities
"
"
WHERE
"
"
event_id != ?
"
"
AND room_id = ?
"
)
# TODO we should not commit yet
txn
.
execute
(
sql
,
(
event_id
,
room_id
))
# TODO flush the cache then commit
return
txn
.
rowcount
return
await
self
.
db_pool
.
runInteraction
(
"
delete_forward_extremities_for_room
"
,
delete_forward_extremities_for_room_txn
,
)
async
def
get_forward_extremities_for_room
(
self
,
room_id
:
str
)
->
List
[
Dict
]:
"""
Get list of forward extremities for a room.
"""
def
get_forward_extremities_for_room_txn
(
txn
):
sql
=
(
"
SELECT event_id, state_group FROM event_forward_extremities NATURAL JOIN event_to_state_groups
"
...
...
@@ -16,5 +63,5 @@ class EventForwardExtremitiesStore(SQLBaseStore):
return
[{
"
event_id
"
:
row
[
0
],
"
state_group
"
:
row
[
1
]}
for
row
in
rows
]
return
await
self
.
db_pool
.
runInteraction
(
"
get_forward_extremities_for_room
"
,
get_forward_extremities_for_room_txn
"
get_forward_extremities_for_room
"
,
get_forward_extremities_for_room_txn
,
)
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