forked from MirrorHub/synapse
Stop populating unused table local_invites
. (#7793)
This table is no longer used, so we may as well stop populating it. Removing it would prevent people rolling back to older releases of Synapse, so that can happen in a future release.
This commit is contained in:
parent
67d7756fcf
commit
76dbd7b8d6
5 changed files with 25 additions and 81 deletions
1
changelog.d/7793.misc
Normal file
1
changelog.d/7793.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Stop populating unused table `local_invites`.
|
|
@ -27,12 +27,7 @@ from prometheus_client import Counter
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
import synapse.metrics
|
import synapse.metrics
|
||||||
from synapse.api.constants import (
|
from synapse.api.constants import EventContentFields, EventTypes, RelationTypes
|
||||||
EventContentFields,
|
|
||||||
EventTypes,
|
|
||||||
Membership,
|
|
||||||
RelationTypes,
|
|
||||||
)
|
|
||||||
from synapse.api.room_versions import RoomVersions
|
from synapse.api.room_versions import RoomVersions
|
||||||
from synapse.crypto.event_signing import compute_event_reference_hash
|
from synapse.crypto.event_signing import compute_event_reference_hash
|
||||||
from synapse.events import EventBase # noqa: F401
|
from synapse.events import EventBase # noqa: F401
|
||||||
|
@ -819,7 +814,6 @@ class PersistEventsStore:
|
||||||
"event_reference_hashes",
|
"event_reference_hashes",
|
||||||
"event_search",
|
"event_search",
|
||||||
"event_to_state_groups",
|
"event_to_state_groups",
|
||||||
"local_invites",
|
|
||||||
"state_events",
|
"state_events",
|
||||||
"rejections",
|
"rejections",
|
||||||
"redactions",
|
"redactions",
|
||||||
|
@ -1196,60 +1190,22 @@ class PersistEventsStore:
|
||||||
(event.state_key,),
|
(event.state_key,),
|
||||||
)
|
)
|
||||||
|
|
||||||
# We update the local_invites table only if the event is "current",
|
# We update the local_current_membership table only if the event is
|
||||||
# i.e., its something that has just happened. If the event is an
|
# "current", i.e., its something that has just happened.
|
||||||
# outlier it is only current if its an "out of band membership",
|
#
|
||||||
# like a remote invite or a rejection of a remote invite.
|
# This will usually get updated by the `current_state_events` handling,
|
||||||
is_new_state = not backfilled and (
|
# unless its an outlier, and an outlier is only "current" if it's an "out of
|
||||||
not event.internal_metadata.is_outlier()
|
# band membership", like a remote invite or a rejection of a remote invite.
|
||||||
or event.internal_metadata.is_out_of_band_membership()
|
if (
|
||||||
)
|
self.is_mine_id(event.state_key)
|
||||||
is_mine = self.is_mine_id(event.state_key)
|
and not backfilled
|
||||||
if is_new_state and is_mine:
|
and event.internal_metadata.is_outlier()
|
||||||
if event.membership == Membership.INVITE:
|
and event.internal_metadata.is_out_of_band_membership()
|
||||||
self.db.simple_insert_txn(
|
):
|
||||||
txn,
|
|
||||||
table="local_invites",
|
|
||||||
values={
|
|
||||||
"event_id": event.event_id,
|
|
||||||
"invitee": event.state_key,
|
|
||||||
"inviter": event.sender,
|
|
||||||
"room_id": event.room_id,
|
|
||||||
"stream_id": event.internal_metadata.stream_ordering,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
sql = (
|
|
||||||
"UPDATE local_invites SET stream_id = ?, replaced_by = ? WHERE"
|
|
||||||
" room_id = ? AND invitee = ? AND locally_rejected is NULL"
|
|
||||||
" AND replaced_by is NULL"
|
|
||||||
)
|
|
||||||
|
|
||||||
txn.execute(
|
|
||||||
sql,
|
|
||||||
(
|
|
||||||
event.internal_metadata.stream_ordering,
|
|
||||||
event.event_id,
|
|
||||||
event.room_id,
|
|
||||||
event.state_key,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# We also update the `local_current_membership` table with
|
|
||||||
# latest invite info. This will usually get updated by the
|
|
||||||
# `current_state_events` handling, unless its an outlier.
|
|
||||||
if event.internal_metadata.is_outlier():
|
|
||||||
# This should only happen for out of band memberships, so
|
|
||||||
# we add a paranoia check.
|
|
||||||
assert event.internal_metadata.is_out_of_band_membership()
|
|
||||||
|
|
||||||
self.db.simple_upsert_txn(
|
self.db.simple_upsert_txn(
|
||||||
txn,
|
txn,
|
||||||
table="local_current_membership",
|
table="local_current_membership",
|
||||||
keyvalues={
|
keyvalues={"room_id": event.room_id, "user_id": event.state_key},
|
||||||
"room_id": event.room_id,
|
|
||||||
"user_id": event.state_key,
|
|
||||||
},
|
|
||||||
values={
|
values={
|
||||||
"event_id": event.event_id,
|
"event_id": event.event_id,
|
||||||
"membership": event.membership,
|
"membership": event.membership,
|
||||||
|
@ -1591,16 +1547,8 @@ class PersistEventsStore:
|
||||||
create a leave event for it.
|
create a leave event for it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sql = (
|
|
||||||
"UPDATE local_invites SET stream_id = ?, locally_rejected = ? WHERE"
|
|
||||||
" room_id = ? AND invitee = ? AND locally_rejected is NULL"
|
|
||||||
" AND replaced_by is NULL"
|
|
||||||
)
|
|
||||||
|
|
||||||
def f(txn, stream_ordering):
|
def f(txn, stream_ordering):
|
||||||
txn.execute(sql, (stream_ordering, True, room_id, user_id))
|
# Clear this entry from `local_current_membership`.
|
||||||
|
|
||||||
# We also clear this entry from `local_current_membership`.
|
|
||||||
# Ideally we'd point to a leave event, but we don't have one, so
|
# Ideally we'd point to a leave event, but we don't have one, so
|
||||||
# nevermind.
|
# nevermind.
|
||||||
self.db.simple_delete_txn(
|
self.db.simple_delete_txn(
|
||||||
|
|
|
@ -82,10 +82,7 @@ class EventsWorkerStore(SQLBaseStore):
|
||||||
# We are the process in charge of generating stream ids for events,
|
# We are the process in charge of generating stream ids for events,
|
||||||
# so instantiate ID generators based on the database
|
# so instantiate ID generators based on the database
|
||||||
self._stream_id_gen = StreamIdGenerator(
|
self._stream_id_gen = StreamIdGenerator(
|
||||||
db_conn,
|
db_conn, "events", "stream_ordering",
|
||||||
"events",
|
|
||||||
"stream_ordering",
|
|
||||||
extra_tables=[("local_invites", "stream_id")],
|
|
||||||
)
|
)
|
||||||
self._backfill_id_gen = StreamIdGenerator(
|
self._backfill_id_gen = StreamIdGenerator(
|
||||||
db_conn,
|
db_conn,
|
||||||
|
|
|
@ -361,7 +361,6 @@ class PurgeEventsStore(StateGroupWorkerStore, SQLBaseStore):
|
||||||
"event_push_summary",
|
"event_push_summary",
|
||||||
"pusher_throttle",
|
"pusher_throttle",
|
||||||
"group_summary_rooms",
|
"group_summary_rooms",
|
||||||
"local_invites",
|
|
||||||
"room_account_data",
|
"room_account_data",
|
||||||
"room_tags",
|
"room_tags",
|
||||||
"local_current_membership",
|
"local_current_membership",
|
||||||
|
|
|
@ -213,7 +213,6 @@ class PurgeRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"event_push_summary",
|
"event_push_summary",
|
||||||
"pusher_throttle",
|
"pusher_throttle",
|
||||||
"group_summary_rooms",
|
"group_summary_rooms",
|
||||||
"local_invites",
|
|
||||||
"room_account_data",
|
"room_account_data",
|
||||||
"room_tags",
|
"room_tags",
|
||||||
# "state_groups", # Current impl leaves orphaned state groups around.
|
# "state_groups", # Current impl leaves orphaned state groups around.
|
||||||
|
|
Loading…
Reference in a new issue