mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-04 22:48:52 -04:00
Merge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes
This commit is contained in:
commit
4abecb7b02
14 changed files with 152 additions and 101 deletions
|
@ -436,15 +436,27 @@ class DeviceStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
def _mark_as_sent_devices_by_remote_txn(self, txn, destination, stream_id):
|
||||
# First we DELETE all rows such that only the latest row for each
|
||||
# (destination, user_id is left. We do this by selecting first and
|
||||
# deleting.
|
||||
sql = """
|
||||
SELECT user_id, coalesce(max(stream_id), 0) FROM device_lists_outbound_pokes
|
||||
WHERE destination = ? AND stream_id <= ?
|
||||
GROUP BY user_id
|
||||
HAVING count(*) > 1
|
||||
"""
|
||||
txn.execute(sql, (destination, stream_id,))
|
||||
rows = txn.fetchall()
|
||||
|
||||
sql = """
|
||||
DELETE FROM device_lists_outbound_pokes
|
||||
WHERE destination = ? AND stream_id < (
|
||||
SELECT coalesce(max(stream_id), 0) FROM device_lists_outbound_pokes
|
||||
WHERE destination = ? AND stream_id <= ?
|
||||
)
|
||||
WHERE destination = ? AND user_id = ? AND stream_id < ?
|
||||
"""
|
||||
txn.execute(sql, (destination, destination, stream_id,))
|
||||
txn.executemany(
|
||||
sql, ((destination, row[0], row[1],) for row in rows)
|
||||
)
|
||||
|
||||
# Mark everything that is left as sent
|
||||
sql = """
|
||||
UPDATE device_lists_outbound_pokes SET sent = ?
|
||||
WHERE destination = ? AND stream_id <= ?
|
||||
|
@ -545,18 +557,22 @@ class DeviceStore(SQLBaseStore):
|
|||
(destination, user_id) tuple to ensure that the prev_ids remain correct
|
||||
if the server does come back.
|
||||
"""
|
||||
now = self._clock.time_msec()
|
||||
yesterday = self._clock.time_msec() - 24 * 60 * 60 * 1000
|
||||
|
||||
def _prune_txn(txn):
|
||||
select_sql = """
|
||||
SELECT destination, user_id, max(stream_id) as stream_id
|
||||
FROM device_lists_outbound_pokes
|
||||
GROUP BY destination, user_id
|
||||
HAVING min(ts) < ? AND count(*) > 1
|
||||
"""
|
||||
|
||||
txn.execute(select_sql)
|
||||
txn.execute(select_sql, (yesterday,))
|
||||
rows = txn.fetchall()
|
||||
|
||||
if not rows:
|
||||
return
|
||||
|
||||
delete_sql = """
|
||||
DELETE FROM device_lists_outbound_pokes
|
||||
WHERE ts < ? AND destination = ? AND user_id = ? AND stream_id < ?
|
||||
|
@ -565,11 +581,13 @@ class DeviceStore(SQLBaseStore):
|
|||
txn.executemany(
|
||||
delete_sql,
|
||||
(
|
||||
(now, row["destination"], row["user_id"], row["stream_id"])
|
||||
(yesterday, row[0], row[1], row[2])
|
||||
for row in rows
|
||||
)
|
||||
)
|
||||
|
||||
logger.info("Pruned %d device list outbound pokes", txn.rowcount)
|
||||
|
||||
return self.runInteraction(
|
||||
"_prune_old_outbound_device_pokes", _prune_txn
|
||||
)
|
||||
|
|
|
@ -129,7 +129,7 @@ class EventFederationStore(SQLBaseStore):
|
|||
room_id,
|
||||
)
|
||||
|
||||
@cached()
|
||||
@cached(max_entries=5000, iterable=True)
|
||||
def get_latest_event_ids_in_room(self, room_id):
|
||||
return self._simple_select_onecol(
|
||||
table="event_forward_extremities",
|
||||
|
|
|
@ -28,6 +28,7 @@ from synapse.util.metrics import Measure
|
|||
from synapse.api.constants import EventTypes
|
||||
from synapse.api.errors import SynapseError
|
||||
from synapse.state import resolve_events
|
||||
from synapse.util.caches.descriptors import cached
|
||||
|
||||
from canonicaljson import encode_canonical_json
|
||||
from collections import deque, namedtuple, OrderedDict
|
||||
|
@ -564,16 +565,12 @@ class EventsStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
for member in members_changed:
|
||||
txn.call_after(self.get_rooms_for_user.invalidate, (member,))
|
||||
self._invalidate_cache_and_stream(
|
||||
txn, self.get_rooms_for_user, (member,)
|
||||
)
|
||||
|
||||
txn.call_after(self.get_users_in_room.invalidate, (room_id,))
|
||||
|
||||
# Add an entry to the current_state_resets table to record the point
|
||||
# where we clobbered the current state
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table="current_state_resets",
|
||||
values={"event_stream_ordering": max_stream_order}
|
||||
self._invalidate_cache_and_stream(
|
||||
txn, self.get_users_in_room, (room_id,)
|
||||
)
|
||||
|
||||
for room_id, new_extrem in new_forward_extremeties.items():
|
||||
|
@ -1581,6 +1578,7 @@ class EventsStore(SQLBaseStore):
|
|||
"""The current minimum token that backfilled events have reached"""
|
||||
return -self._backfill_id_gen.get_current_token()
|
||||
|
||||
@cached(num_args=5, max_entries=10)
|
||||
def get_all_new_events(self, last_backfill_id, last_forward_id,
|
||||
current_backfill_id, current_forward_id, limit):
|
||||
"""Get all the new events that have arrived at the server either as
|
||||
|
@ -1612,15 +1610,6 @@ class EventsStore(SQLBaseStore):
|
|||
else:
|
||||
upper_bound = current_forward_id
|
||||
|
||||
sql = (
|
||||
"SELECT event_stream_ordering FROM current_state_resets"
|
||||
" WHERE ? < event_stream_ordering"
|
||||
" AND event_stream_ordering <= ?"
|
||||
" ORDER BY event_stream_ordering ASC"
|
||||
)
|
||||
txn.execute(sql, (last_forward_id, upper_bound))
|
||||
state_resets = txn.fetchall()
|
||||
|
||||
sql = (
|
||||
"SELECT event_stream_ordering, event_id, state_group"
|
||||
" FROM ex_outlier_stream"
|
||||
|
@ -1632,7 +1621,6 @@ class EventsStore(SQLBaseStore):
|
|||
forward_ex_outliers = txn.fetchall()
|
||||
else:
|
||||
new_forward_events = []
|
||||
state_resets = []
|
||||
forward_ex_outliers = []
|
||||
|
||||
sql = (
|
||||
|
@ -1672,7 +1660,6 @@ class EventsStore(SQLBaseStore):
|
|||
return AllNewEventsResult(
|
||||
new_forward_events, new_backfill_events,
|
||||
forward_ex_outliers, backward_ex_outliers,
|
||||
state_resets,
|
||||
)
|
||||
return self.runInteraction("get_all_new_events", get_all_new_events_txn)
|
||||
|
||||
|
@ -1898,5 +1885,4 @@ class EventsStore(SQLBaseStore):
|
|||
AllNewEventsResult = namedtuple("AllNewEventsResult", [
|
||||
"new_forward_events", "new_backfill_events",
|
||||
"forward_ex_outliers", "backward_ex_outliers",
|
||||
"state_resets"
|
||||
])
|
||||
|
|
|
@ -66,8 +66,6 @@ class RoomMemberStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
for event in events:
|
||||
txn.call_after(self.get_rooms_for_user.invalidate, (event.state_key,))
|
||||
txn.call_after(self.get_users_in_room.invalidate, (event.room_id,))
|
||||
txn.call_after(
|
||||
self._membership_stream_cache.entity_has_changed,
|
||||
event.state_key, event.internal_metadata.stream_ordering
|
||||
|
@ -220,7 +218,7 @@ class RoomMemberStore(SQLBaseStore):
|
|||
" ON e.event_id = c.event_id"
|
||||
" AND m.room_id = c.room_id"
|
||||
" AND m.user_id = c.state_key"
|
||||
" WHERE %s"
|
||||
" WHERE c.type = 'm.room.member' AND %s"
|
||||
) % (where_clause,)
|
||||
|
||||
txn.execute(sql, args)
|
||||
|
@ -266,7 +264,7 @@ class RoomMemberStore(SQLBaseStore):
|
|||
" ON m.event_id = c.event_id "
|
||||
" AND m.room_id = c.room_id "
|
||||
" AND m.user_id = c.state_key"
|
||||
" WHERE %(where)s"
|
||||
" WHERE c.type = 'm.room.member' AND %(where)s"
|
||||
) % {
|
||||
"where": where_clause,
|
||||
}
|
||||
|
|
17
synapse/storage/schema/delta/40/current_state_idx.sql
Normal file
17
synapse/storage/schema/delta/40/current_state_idx.sql
Normal file
|
@ -0,0 +1,17 @@
|
|||
/* Copyright 2017 OpenMarket Ltd
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
INSERT INTO background_updates (update_name, progress_json) VALUES
|
||||
('current_state_members_idx', '{}');
|
|
@ -49,6 +49,7 @@ class StateStore(SQLBaseStore):
|
|||
|
||||
STATE_GROUP_DEDUPLICATION_UPDATE_NAME = "state_group_state_deduplication"
|
||||
STATE_GROUP_INDEX_UPDATE_NAME = "state_group_state_type_index"
|
||||
CURRENT_STATE_INDEX_UPDATE_NAME = "current_state_members_idx"
|
||||
|
||||
def __init__(self, hs):
|
||||
super(StateStore, self).__init__(hs)
|
||||
|
@ -60,6 +61,13 @@ class StateStore(SQLBaseStore):
|
|||
self.STATE_GROUP_INDEX_UPDATE_NAME,
|
||||
self._background_index_state,
|
||||
)
|
||||
self.register_background_index_update(
|
||||
self.CURRENT_STATE_INDEX_UPDATE_NAME,
|
||||
index_name="current_state_events_member_index",
|
||||
table="current_state_events",
|
||||
columns=["state_key"],
|
||||
where_clause="type='m.room.member'",
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_state_groups_ids(self, room_id, event_ids):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue