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

Implement "event_fields" in filters #1638

Merged
merged 8 commits into from
Nov 22, 2016
Merged

Implement "event_fields" in filters #1638

merged 8 commits into from
Nov 22, 2016

Conversation

kegsay
Copy link
Member

@kegsay 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.

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace the 3 lines with:

sub_out_dict = sub_out_dict.setdefault(sub_field, {})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the args are incorrect this should raise an exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@erikjohnston
Copy link
Member

LGTM

@kegsay kegsay merged commit d4a459f into develop Nov 22, 2016
@richvdh richvdh deleted the kegan/sync-event-fields branch December 1, 2016 14:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants