Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

initial cut at a room summary API #3574

Merged
merged 52 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7b7fd27
untested attempt at deduplicating lazy-loaded members
ara4n Jun 3, 2018
c341d81
Merge branch 'develop' into matthew/remove_redundant_lazy_members
ara4n Jun 10, 2018
f7bd5da
add include_redundant_members filter option & make it work
ara4n Jun 10, 2018
589e5aa
merge and apply isort
ara4n Jul 19, 2018
8e66dd1
merge in #2970
ara4n Jul 19, 2018
a08b37b
fix bad merge
ara4n Jul 19, 2018
7362e6c
make /context lazyload & filter aware
ara4n Jul 20, 2018
cd28d2f
speed up /members and add at= and membership params
ara4n Jul 20, 2018
a17f0b6
make it work
ara4n Jul 20, 2018
9ba6ef2
Merge branch 'matthew/lazy_load_apis' into matthew/members_at
ara4n Jul 20, 2018
c6117fa
make it work
ara4n Jul 20, 2018
8f1585d
make filtering work
ara4n Jul 21, 2018
42308c0
initial cut at a room summary API
ara4n Jul 23, 2018
0beeecf
remove debug log
ara4n Jul 23, 2018
63ce31b
namespace the summary fields correctly
ara4n Jul 23, 2018
c8cbede
fix key typo
bwindels Jul 23, 2018
f9c3c26
Merge branch 'matthew/filter_members' into matthew/remove_redundant_l…
ara4n Jul 23, 2018
c2870ab
Merge branch 'matthew/remove_redundant_lazy_members' into matthew/laz…
ara4n Jul 23, 2018
ffb7a4c
Merge branch 'matthew/lazy_load_apis' into matthew/members_at
ara4n Jul 23, 2018
c1c6ff1
Merge branch 'matthew/members_at' into matthew/room_summary
ara4n Jul 23, 2018
7d99b0e
changelog
ara4n Jul 23, 2018
cd27a77
changelog
ara4n Jul 23, 2018
4018a6d
changelog
ara4n Jul 23, 2018
c238a88
changelog
ara4n Jul 23, 2018
1ba3683
return the correct counts & self-exclude from heros
ara4n Jul 24, 2018
f129390
spell heroes correctly
ara4n Jul 24, 2018
e61071a
fix heroes definition to match MSC
ara4n Jul 24, 2018
d32e5f8
Merge branch 'matthew/filter_members' into matthew/remove_redundant_l…
ara4n Jul 24, 2018
238f750
deduplicating redundant members via event_id rather than mxid
ara4n Jul 24, 2018
2a79e1a
Merge branch 'matthew/remove_redundant_lazy_members' into matthew/laz…
ara4n Jul 24, 2018
48f3e43
Merge branch 'matthew/lazy_load_apis' into matthew/members_at
ara4n Jul 24, 2018
7cc81ed
Merge branch 'matthew/members_at' into matthew/room_summary
ara4n Jul 24, 2018
08af91d
fix merge fail
ara4n Jul 24, 2018
e76254b
Merge branch 'matthew/members_at' into matthew/room_summary
ara4n Jul 24, 2018
e952368
incorporate review
ara4n Jul 30, 2018
2d9c062
Merge branch 'develop' into matthew/members_at
ara4n Aug 12, 2018
eebee08
convert /members?at= to take a stream token
ara4n Aug 12, 2018
5df2c36
Merge branch 'develop' into matthew/room_summary
ara4n Aug 12, 2018
d0c0d72
incorporate all the review feedback
ara4n Aug 12, 2018
b327e07
fix use of get_recent_event_ids_for_room
ara4n Aug 12, 2018
9e4acb7
Merge branch 'matthew/members_at' into matthew/room_summary
ara4n Aug 12, 2018
32bf4fa
return early rather than big if blocks
ara4n Aug 14, 2018
859ad35
incorporate PR review
ara4n Aug 14, 2018
dd4498f
Merge branch 'develop' into matthew/members_at
ara4n Aug 14, 2018
217d5dd
Merge branch 'develop' into matthew/members_at
ara4n Aug 15, 2018
8442478
Merge branch 'matthew/members_at' into matthew/room_summary
ara4n Aug 15, 2018
f5189b9
remove incorrectly reintroduced method
richvdh Aug 15, 2018
0d5770d
cleanups
richvdh Aug 15, 2018
c2d9c96
Merge branch 'matthew/members_at' into matthew/room_summary
richvdh Aug 15, 2018
dc085c0
Merge remote-tracking branch 'origin/develop' into matthew/room_summary
richvdh Aug 15, 2018
7306074
remove spurious changelogs
richvdh Aug 15, 2018
c3cdc21
factor out get_lazy_loaded_members_cache
ara4n Aug 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3331.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add support for the include_redundant_members filter param as per MSC1227
1 change: 1 addition & 0 deletions changelog.d/3567.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make the /context API filter & lazy-load aware as per MSC1227
1 change: 1 addition & 0 deletions changelog.d/3568.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
speed up /members API and add `at` and `membership` params as per MSC1227
1 change: 1 addition & 0 deletions changelog.d/3574.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implement `summary` block in /sync response as per MSC688
9 changes: 9 additions & 0 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
"lazy_load_members": {
"type": "boolean"
},
"include_redundant_members": {
"type": "boolean"
},
}
}

Expand Down Expand Up @@ -267,6 +270,9 @@ def ephemeral_limit(self):
def lazy_load_members(self):
return self._room_state_filter.lazy_load_members()

def include_redundant_members(self):
return self._room_state_filter.include_redundant_members()

def filter_presence(self, events):
return self._presence_filter.filter(events)

Expand Down Expand Up @@ -426,6 +432,9 @@ def limit(self):
def lazy_load_members(self):
return self.filter_json.get("lazy_load_members", False)

def include_redundant_members(self):
return self.filter_json.get("include_redundant_members", False)


def _matches_wildcard(actual_value, filter_value):
if filter_value.endswith("*"):
Expand Down
52 changes: 48 additions & 4 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,49 @@ def get_room_data(self, user_id=None, room_id=None,
defer.returnValue(data)

@defer.inlineCallbacks
def get_state_events(self, user_id, room_id, is_guest=False):
def _check_in_room_or_world_readable(self, room_id, user_id):
try:
# check_user_was_in_room will return the most recent membership
# event for the user if:
# * The user is a non-guest user, and was ever in the room
# * The user is a guest user, and has joined the room
# else it will throw.
member_event = yield self.auth.check_user_was_in_room(room_id, user_id)
defer.returnValue((member_event.membership, member_event.event_id))
return
except AuthError:
visibility = yield self.state_handler.get_current_state(
room_id, EventTypes.RoomHistoryVisibility, ""
)
if (
visibility and
visibility.content["history_visibility"] == "world_readable"
):
defer.returnValue((Membership.JOIN, None))
return
raise AuthError(
403, "Guest access not allowed", errcode=Codes.GUEST_ACCESS_FORBIDDEN
)

@defer.inlineCallbacks
def get_state_events(
self, user_id, room_id, types=None, filtered_types=None,
at_event=None, is_guest=False
):
"""Retrieve all state events for a given room. If the user is
joined to the room then return the current state. If the user has
left the room return the state events from when they left.
left the room return the state events from when they left. If an explicit
'at' parameter is passed, return the state events as of that event.

Args:
user_id(str): The user requesting state events.
room_id(str): The room ID to get all state events from.
types(list[(Str, (Str|None))]): the (type, state_key)s to return
results for.
filtered_types(list[Str]): the list of types to apply the types filter
to.
at_event(str): the event_id we are requesting the state as of
is_guest(Boolean): whether this user is a guest
Returns:
A list of dicts representing state events. [{}, {}, {}]
"""
Expand All @@ -98,10 +133,19 @@ def get_state_events(self, user_id, room_id, is_guest=False):
)

if membership == Membership.JOIN:
room_state = yield self.state.get_current_state(room_id)
if at_event:
room_state = yield self.store.get_state_for_events(
[at_event], types, filtered_types=filtered_types
)
room_state = room_state[at_event]
else:
state_ids = yield self.store.get_filtered_current_state_ids(
room_id, types, filtered_types=filtered_types
)
room_state = yield self.store.get_events(state_ids.values())
elif membership == Membership.LEAVE:
room_state = yield self.store.get_state_for_events(
[membership_event_id], None
[membership_event_id], types, filtered_types=filtered_types
)
room_state = room_state[membership_event_id]

Expand Down
24 changes: 21 additions & 3 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def __init__(self, hs):
self.store = hs.get_datastore()

@defer.inlineCallbacks
def get_event_context(self, user, room_id, event_id, limit):
def get_event_context(self, user, room_id, event_id, limit, event_filter):
"""Retrieves events, pagination tokens and state around a given event
in a room.

Expand All @@ -411,6 +411,8 @@ def get_event_context(self, user, room_id, event_id, limit):
event_id (str)
limit (int): The maximum number of events to return in total
(excluding state).
event_filter (Filter|None): the filter to apply to the events returned
(excluding the target event_id)

Returns:
dict, or None if the event isn't found
Expand Down Expand Up @@ -445,7 +447,7 @@ def filter_evts(events):
)

results = yield self.store.get_events_around(
room_id, event_id, before_limit, after_limit
room_id, event_id, before_limit, after_limit, event_filter
)

results["events_before"] = yield filter_evts(results["events_before"])
Expand All @@ -457,8 +459,24 @@ def filter_evts(events):
else:
last_event_id = event_id

types = None
filtered_types = None
if event_filter and event_filter.lazy_load_members():
members = {}
for ev in (
results["events_before"] +
[results["event"]] +
results["events_after"]
):
members[ev.sender] = True
filtered_types = [EventTypes.Member]
types = [(EventTypes.Member, member) for member in members.keys()]

# XXX: why do we return the state as of the last event rather than the
# first? Shouldn't we be consistent with /sync?

state = yield self.store.get_state_for_events(
[last_event_id], None
[last_event_id], types, filtered_types=filtered_types
)
results["state"] = list(state[last_event_id].values())

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def search(self, user, content, batch=None):
contexts = {}
for event in allowed_events:
res = yield self.store.get_events_around(
event.room_id, event.event_id, before_limit, after_limit
event.room_id, event.event_id, before_limit, after_limit,
)

logger.info(
Expand Down
Loading