Merge pull request #736 from matrix-org/markjh/slave_invited_rooms_for_user

Replicate get_invited_rooms_for_user
This commit is contained in:
Mark Haines 2016-04-19 15:46:00 +01:00
commit 4084c58aa1
2 changed files with 19 additions and 2 deletions

View File

@ -68,6 +68,9 @@ class SlavedEventStore(BaseSlavedStore):
_get_current_state_for_key = StateStore.__dict__[ _get_current_state_for_key = StateStore.__dict__[
"_get_current_state_for_key" "_get_current_state_for_key"
] ]
get_invited_rooms_for_user = RoomMemberStore.__dict__[
"get_invited_rooms_for_user"
]
get_event = DataStore.get_event.__func__ get_event = DataStore.get_event.__func__
get_current_state = DataStore.get_current_state.__func__ get_current_state = DataStore.get_current_state.__func__
@ -82,6 +85,7 @@ class SlavedEventStore(BaseSlavedStore):
get_room_events_stream_for_room = ( get_room_events_stream_for_room = (
DataStore.get_room_events_stream_for_room.__func__ DataStore.get_room_events_stream_for_room.__func__
) )
_set_before_and_after = DataStore._set_before_and_after _set_before_and_after = DataStore._set_before_and_after
_get_events = DataStore._get_events.__func__ _get_events = DataStore._get_events.__func__
@ -147,11 +151,11 @@ class SlavedEventStore(BaseSlavedStore):
internal = json.loads(row[1]) internal = json.loads(row[1])
event_json = json.loads(row[2]) event_json = json.loads(row[2])
event = FrozenEvent(event_json, internal_metadata_dict=internal) event = FrozenEvent(event_json, internal_metadata_dict=internal)
self._invalidate_caches_for_event( self.invalidate_caches_for_event(
event, backfilled, reset_state=position in state_resets event, backfilled, reset_state=position in state_resets
) )
def _invalidate_caches_for_event(self, event, backfilled, reset_state): def invalidate_caches_for_event(self, event, backfilled, reset_state):
if reset_state: if reset_state:
self._get_current_state_for_key.invalidate_all() self._get_current_state_for_key.invalidate_all()
self.get_rooms_for_user.invalidate_all() self.get_rooms_for_user.invalidate_all()
@ -182,6 +186,7 @@ class SlavedEventStore(BaseSlavedStore):
# self._membership_stream_cache.entity_has_changed( # self._membership_stream_cache.entity_has_changed(
# event.state_key, event.internal_metadata.stream_ordering # event.state_key, event.internal_metadata.stream_ordering
# ) # )
self.get_invited_rooms_for_user.invalidate((event.state_key,))
if not event.is_state(): if not event.is_state():
return return

View File

@ -251,6 +251,18 @@ class SlavedEventStoreTestCase(BaseSlavedStoreTestCase):
redacted = FrozenEvent(msg_dict, msg.internal_metadata.get_dict()) redacted = FrozenEvent(msg_dict, msg.internal_metadata.get_dict())
yield self.check("get_event", [msg.event_id], redacted) yield self.check("get_event", [msg.event_id], redacted)
@defer.inlineCallbacks
def test_invites(self):
yield self.check("get_invited_rooms_for_user", [USER_ID_2], [])
event = yield self.persist(
type="m.room.member", key=USER_ID_2, membership="invite"
)
yield self.replicate()
yield self.check("get_invited_rooms_for_user", [USER_ID_2], [RoomsForUser(
ROOM_ID, USER_ID, "invite", event.event_id,
event.internal_metadata.stream_ordering
)])
event_id = 0 event_id = 0
@defer.inlineCallbacks @defer.inlineCallbacks