Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Implement "event_fields" in filters #1638

Merged
merged 8 commits into from Nov 22, 2016

Conversation

Projects
None yet
2 participants
Contributor

Kegsay commented Nov 22, 2016

http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter

event_fields	[string]

List of event fields to include. If this list is absent then all fields are included. The entries may include '.' charaters to indicate sub-fields. So ['content.body'] will include the 'body' field of the 'content' object. A literal '.' character in a field name may be escaped using a ''. A server may include more fields than were requested.

Kegsay added some commits Nov 21, 2016

Move event_fields filtering to serialize_event
Also make it an inclusive not exclusive filter, as the spec demands.

You've mentioned performance a couple of times, I wonder if its worth doing a quick benchmark to see how long it takes to serialise events?

synapse/events/utils.py
+ for sub_field in field:
+ if sub_field not in sub_out_dict:
+ sub_out_dict[sub_field] = {}
+ sub_out_dict = sub_out_dict[sub_field]
@erikjohnston

erikjohnston Nov 22, 2016

Owner

You can replace the 3 lines with:

sub_out_dict = sub_out_dict.setdefault(sub_field, {})
@Kegsay

Kegsay Nov 22, 2016

Contributor

Done.

synapse/events/utils.py
+ # for each element of the output array of arrays:
+ # remove escaping so we can use the right key names. This purposefully avoids
+ # using list comprehensions to avoid needless allocations as this may be called
+ # on a lot of events.
@erikjohnston

erikjohnston Nov 22, 2016

Owner

I did a quick benchmark and the following list comprehension is actually quicker:

split_fields[:] = [ [field.replace(r'\.', r'.') for field in field_array] for field_array in split_fields]
@erikjohnston

erikjohnston Nov 22, 2016

Owner

And if we really cared about performance, we would pull this up to be calculated when we initially parsed the filter

@Kegsay

Kegsay Nov 22, 2016

Contributor

Done.

synapse/events/utils.py
+ d = event_format(d)
+
+ if (only_event_fields and isinstance(only_event_fields, list) and
+ all(isinstance(f, basestring) for f in only_event_fields)):
@erikjohnston

erikjohnston Nov 22, 2016

Owner

If the args are incorrect this should raise an exception.

@Kegsay

Kegsay Nov 22, 2016

Contributor

Done.

Owner

erikjohnston commented Nov 22, 2016

LGTM

@Kegsay Kegsay merged commit d4a459f into develop Nov 22, 2016

9 of 10 checks passed

Sytest Dendron (Commit) Build #1142 origin/kegan/sync-event-fields failed in 2 min 12 sec
Details
Flake8 + Packaging (Commit) Build #2076 origin/kegan/sync-event-fields succeeded in 55 sec
Details
Flake8 + Packaging (Merged PR) Build finished.
Details
Sytest Dendron (Merged PR) Build finished.
Details
Sytest Postgres (Commit) Build #1979 origin/kegan/sync-event-fields succeeded in 9 min 20 sec
Details
Sytest Postgres (Merged PR) Build finished.
Details
Sytest SQLite (Commit) Build #2025 origin/kegan/sync-event-fields succeeded in 6 min 22 sec
Details
Sytest SQLite (Merged PR) Build finished.
Details
Unit Tests (Commit) Build #2107 origin/kegan/sync-event-fields succeeded in 3 min 19 sec
Details
Unit Tests (Merged PR) Build finished.
Details

@Kegsay Kegsay referenced this pull request in matrix-org/matrix-appservice-irc Nov 25, 2016

Closed

Freenode bridge outage (19-21 Nov) #288

@richvdh richvdh deleted the kegan/sync-event-fields branch Dec 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment