Address pr feedback
* docs updates * prettify SQL * add missing copyright * cursor_to_dict * update touched files copyright years Signed-off-by: Jason Robinson <jasonr@matrix.org>
This commit is contained in:
parent
0b77329fe2
commit
da16d06301
|
@ -516,11 +516,8 @@ optionally be specified, e.g.:
|
||||||
# Forward Extremities Admin API
|
# Forward Extremities Admin API
|
||||||
|
|
||||||
Enables querying and deleting forward extremities from rooms. When a lot of forward
|
Enables querying and deleting forward extremities from rooms. When a lot of forward
|
||||||
extremities accumulate in a room, performance can become degraded.
|
extremities accumulate in a room, performance can become degraded. For details, see
|
||||||
|
[#1760](https://github.com/matrix-org/synapse/issues/1760).
|
||||||
When using this API endpoint to delete any extra forward extremities for a room,
|
|
||||||
the server does not need to be restarted as the relevant caches will be cleared
|
|
||||||
in the API call.
|
|
||||||
|
|
||||||
## Check for forward extremities
|
## Check for forward extremities
|
||||||
|
|
||||||
|
@ -537,7 +534,7 @@ A response as follows will be returned:
|
||||||
"count": 1,
|
"count": 1,
|
||||||
"results": [
|
"results": [
|
||||||
{
|
{
|
||||||
"event_id": "$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdfgh",
|
"event_id": "$M5SP266vsnxctfwFgFLNceaCo3ujhRtg_NiiHabcdefgh",
|
||||||
"state_group": 439
|
"state_group": 439
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -561,6 +558,3 @@ that were deleted.
|
||||||
"deleted": 1
|
"deleted": 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The cache `get_latest_event_ids_in_room` will be invalidated, if any forward extremities
|
|
||||||
were deleted.
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2014-2016 OpenMarket Ltd
|
# Copyright 2014-2016 OpenMarket Ltd
|
||||||
# Copyright 2018-2019 New Vector Ltd
|
# Copyright 2018-2019 New Vector Ltd
|
||||||
|
# Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
# Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2014-2016 OpenMarket Ltd
|
# Copyright 2014-2016 OpenMarket Ltd
|
||||||
# Copyright 2018 New Vector Ltd
|
# Copyright 2018 New Vector Ltd
|
||||||
# Copyright 2019 The Matrix.org Foundation C.I.C.
|
# Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,3 +1,18 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
|
@ -19,19 +34,19 @@ class EventForwardExtremitiesStore(SQLBaseStore):
|
||||||
|
|
||||||
def delete_forward_extremities_for_room_txn(txn):
|
def delete_forward_extremities_for_room_txn(txn):
|
||||||
# First we need to get the event_id to not delete
|
# First we need to get the event_id to not delete
|
||||||
sql = (
|
sql = """
|
||||||
"SELECT "
|
SELECT
|
||||||
" last_value(event_id) OVER w AS event_id"
|
last_value(event_id) OVER w AS event_id
|
||||||
" FROM event_forward_extremities"
|
FROM event_forward_extremities
|
||||||
" NATURAL JOIN events"
|
NATURAL JOIN events
|
||||||
" where room_id = ?"
|
WHERE room_id = ?
|
||||||
" WINDOW w AS ("
|
WINDOW w AS (
|
||||||
" PARTITION BY room_id"
|
PARTITION BY room_id
|
||||||
" ORDER BY stream_ordering"
|
ORDER BY stream_ordering
|
||||||
" range between unbounded preceding and unbounded following"
|
range between unbounded preceding and unbounded following
|
||||||
" )"
|
)
|
||||||
" ORDER BY stream_ordering"
|
ORDER BY stream_ordering
|
||||||
)
|
"""
|
||||||
txn.execute(sql, (room_id,))
|
txn.execute(sql, (room_id,))
|
||||||
rows = txn.fetchall()
|
rows = txn.fetchall()
|
||||||
try:
|
try:
|
||||||
|
@ -47,12 +62,10 @@ class EventForwardExtremitiesStore(SQLBaseStore):
|
||||||
raise SynapseError(400, msg)
|
raise SynapseError(400, msg)
|
||||||
|
|
||||||
# Now delete the extra forward extremities
|
# Now delete the extra forward extremities
|
||||||
sql = (
|
sql = """
|
||||||
"DELETE FROM event_forward_extremities "
|
DELETE FROM event_forward_extremities
|
||||||
"WHERE"
|
WHERE event_id != ? AND room_id = ?
|
||||||
" event_id != ?"
|
"""
|
||||||
" AND room_id = ?"
|
|
||||||
)
|
|
||||||
|
|
||||||
txn.execute(sql, (event_id, room_id))
|
txn.execute(sql, (event_id, room_id))
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -78,14 +91,15 @@ class EventForwardExtremitiesStore(SQLBaseStore):
|
||||||
"""Get list of forward extremities for a room."""
|
"""Get list of forward extremities for a room."""
|
||||||
|
|
||||||
def get_forward_extremities_for_room_txn(txn):
|
def get_forward_extremities_for_room_txn(txn):
|
||||||
sql = (
|
sql = """
|
||||||
"SELECT event_id, state_group FROM event_forward_extremities NATURAL JOIN event_to_state_groups "
|
SELECT event_id, state_group
|
||||||
"WHERE room_id = ?"
|
FROM event_forward_extremities
|
||||||
)
|
NATURAL JOIN event_to_state_groups
|
||||||
|
WHERE room_id = ?
|
||||||
|
"""
|
||||||
|
|
||||||
txn.execute(sql, (room_id,))
|
txn.execute(sql, (room_id,))
|
||||||
rows = txn.fetchall()
|
return self.db_pool.cursor_to_dict(txn)
|
||||||
return [{"event_id": row[0], "state_group": row[1]} for row in rows]
|
|
||||||
|
|
||||||
return await self.db_pool.runInteraction(
|
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,
|
||||||
|
|
Loading…
Reference in New Issue