Merge pull request #3583 from matrix-org/rav/remove_who_forgot_in_room
Remove redundant checks on room forgottenness
This commit is contained in:
commit
93b0722c50
|
@ -0,0 +1 @@
|
||||||
|
Remove redundant checks on who_forgot_in_room
|
|
@ -21,7 +21,6 @@ from canonicaljson import json
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.constants import EventTypes
|
|
||||||
from synapse.push.baserules import list_with_base_rules
|
from synapse.push.baserules import list_with_base_rules
|
||||||
from synapse.storage.appservice import ApplicationServiceWorkerStore
|
from synapse.storage.appservice import ApplicationServiceWorkerStore
|
||||||
from synapse.storage.pusher import PusherWorkerStore
|
from synapse.storage.pusher import PusherWorkerStore
|
||||||
|
@ -250,18 +249,6 @@ class PushRulesWorkerStore(ApplicationServiceWorkerStore,
|
||||||
if uid in local_users_in_room:
|
if uid in local_users_in_room:
|
||||||
user_ids.add(uid)
|
user_ids.add(uid)
|
||||||
|
|
||||||
forgotten = yield self.who_forgot_in_room(
|
|
||||||
event.room_id, on_invalidate=cache_context.invalidate,
|
|
||||||
)
|
|
||||||
|
|
||||||
for row in forgotten:
|
|
||||||
user_id = row["user_id"]
|
|
||||||
event_id = row["event_id"]
|
|
||||||
|
|
||||||
mem_id = current_state_ids.get((EventTypes.Member, user_id), None)
|
|
||||||
if event_id == mem_id:
|
|
||||||
user_ids.discard(user_id)
|
|
||||||
|
|
||||||
rules_by_user = yield self.bulk_get_push_rules(
|
rules_by_user = yield self.bulk_get_push_rules(
|
||||||
user_ids, on_invalidate=cache_context.invalidate,
|
user_ids, on_invalidate=cache_context.invalidate,
|
||||||
)
|
)
|
||||||
|
|
|
@ -461,18 +461,6 @@ class RoomMemberWorkerStore(EventsWorkerStore):
|
||||||
def _get_joined_hosts_cache(self, room_id):
|
def _get_joined_hosts_cache(self, room_id):
|
||||||
return _JoinedHostsCache(self, room_id)
|
return _JoinedHostsCache(self, room_id)
|
||||||
|
|
||||||
@cached()
|
|
||||||
def who_forgot_in_room(self, room_id):
|
|
||||||
return self._simple_select_list(
|
|
||||||
table="room_memberships",
|
|
||||||
retcols=("user_id", "event_id"),
|
|
||||||
keyvalues={
|
|
||||||
"room_id": room_id,
|
|
||||||
"forgotten": 1,
|
|
||||||
},
|
|
||||||
desc="who_forgot"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RoomMemberStore(RoomMemberWorkerStore):
|
class RoomMemberStore(RoomMemberWorkerStore):
|
||||||
def __init__(self, db_conn, hs):
|
def __init__(self, db_conn, hs):
|
||||||
|
@ -581,9 +569,6 @@ class RoomMemberStore(RoomMemberWorkerStore):
|
||||||
txn.execute(sql, (user_id, room_id))
|
txn.execute(sql, (user_id, room_id))
|
||||||
|
|
||||||
txn.call_after(self.did_forget.invalidate, (user_id, room_id))
|
txn.call_after(self.did_forget.invalidate, (user_id, room_id))
|
||||||
self._invalidate_cache_and_stream(
|
|
||||||
txn, self.who_forgot_in_room, (room_id,)
|
|
||||||
)
|
|
||||||
return self.runInteraction("forget_membership", f)
|
return self.runInteraction("forget_membership", f)
|
||||||
|
|
||||||
@cachedInlineCallbacks(num_args=2)
|
@cachedInlineCallbacks(num_args=2)
|
||||||
|
|
|
@ -24,7 +24,6 @@ from twisted.internet import defer
|
||||||
from synapse.api.constants import EventTypes, Membership
|
from synapse.api.constants import EventTypes, Membership
|
||||||
from synapse.events.utils import prune_event
|
from synapse.events.utils import prune_event
|
||||||
from synapse.types import get_domain_from_id
|
from synapse.types import get_domain_from_id
|
||||||
from synapse.util.logcontext import make_deferred_yieldable, preserve_fn
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -76,19 +75,6 @@ def filter_events_for_client(store, user_id, events, is_peeking=False,
|
||||||
types=types,
|
types=types,
|
||||||
)
|
)
|
||||||
|
|
||||||
forgotten = yield make_deferred_yieldable(defer.gatherResults([
|
|
||||||
defer.maybeDeferred(
|
|
||||||
preserve_fn(store.who_forgot_in_room),
|
|
||||||
room_id,
|
|
||||||
)
|
|
||||||
for room_id in frozenset(e.room_id for e in events)
|
|
||||||
], consumeErrors=True))
|
|
||||||
|
|
||||||
# Set of membership event_ids that have been forgotten
|
|
||||||
event_id_forgotten = frozenset(
|
|
||||||
row["event_id"] for rows in forgotten for row in rows
|
|
||||||
)
|
|
||||||
|
|
||||||
ignore_dict_content = yield store.get_global_account_data_by_type_for_user(
|
ignore_dict_content = yield store.get_global_account_data_by_type_for_user(
|
||||||
"m.ignored_user_list", user_id,
|
"m.ignored_user_list", user_id,
|
||||||
)
|
)
|
||||||
|
@ -177,10 +163,7 @@ def filter_events_for_client(store, user_id, events, is_peeking=False,
|
||||||
if membership is None:
|
if membership is None:
|
||||||
membership_event = state.get((EventTypes.Member, user_id), None)
|
membership_event = state.get((EventTypes.Member, user_id), None)
|
||||||
if membership_event:
|
if membership_event:
|
||||||
# XXX why do we do this?
|
membership = membership_event.membership
|
||||||
# https://github.com/matrix-org/synapse/issues/3350
|
|
||||||
if membership_event.event_id not in event_id_forgotten:
|
|
||||||
membership = membership_event.membership
|
|
||||||
|
|
||||||
# if the user was a member of the room at the time of the event,
|
# if the user was a member of the room at the time of the event,
|
||||||
# they can see it.
|
# they can see it.
|
||||||
|
|
Loading…
Reference in New Issue