Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
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
Rewrite presence for performance. #582
Conversation
erikjohnston
added some commits
Feb 12, 2016
erikjohnston
assigned
NegativeMjark
Feb 17, 2016
erikjohnston
added some commits
Feb 17, 2016
erikjohnston
referenced this pull request
in matrix-org/sytest
Feb 18, 2016
Merged
Fix tests for new presence implementation. #187
NegativeMjark
commented on an outdated diff
Feb 18, 2016
synapse/util/wheel_timer.py
| + self.entries = [] | ||
| + self.current_tick = 0 | ||
| + | ||
| + def insert(self, now, obj, then): | ||
| + """Inserts object into timer. | ||
| + | ||
| + Args: | ||
| + now (int): Current time in msec | ||
| + obj (object): Object to be inserted | ||
| + then (int): When to return the object strictly after. | ||
| + """ | ||
| + then_key = int(then / self.bucket_size) + 1 | ||
| + for entry in self.entries: | ||
| + # Add to first bucket we find. This should gracefully handle inserts | ||
| + # for times in the past. | ||
| + if entry.end_key >= then_key: |
NegativeMjark
Contributor
|
NegativeMjark
commented on an outdated diff
Feb 18, 2016
NegativeMjark
commented on the diff
Feb 18, 2016
synapse/storage/__init__.py
| @@ -174,6 +197,27 @@ def _get_cache_dict(self, db_conn, table, entity_column, stream_column, max_valu | ||
| return cache, min_val | ||
| + def _get_active_presence(self, db_conn): | ||
| + """Fetch non-offline presence from the database so that we can register | ||
| + the appropriate time outs. | ||
| + """ | ||
| + | ||
| + sql = ( | ||
| + "SELECT user_id, state, last_active_ts, last_federation_update_ts," | ||
| + " last_user_sync_ts, status_msg, currently_active FROM presence_stream" | ||
| + " WHERE state != ?" | ||
| + ) | ||
| + sql = self.database_engine.convert_param_style(sql) | ||
| + | ||
| + txn = db_conn.cursor() |
|
|
erikjohnston
added some commits
Feb 18, 2016
NegativeMjark
commented on an outdated diff
Feb 18, 2016
synapse/rest/client/v1/presence.py
| @@ -35,8 +35,15 @@ def on_GET(self, request, user_id): | ||
| requester = yield self.auth.get_user_by_req(request) | ||
| user = UserID.from_string(user_id) | ||
| - state = yield self.handlers.presence_handler.get_state( | ||
| - target_user=user, auth_user=requester.user) | ||
| + if requester.user != user: | ||
| + allowed = yield self.handlers.presence_handler.is_visible( | ||
| + observed_user=user, observer_user=requester.user, | ||
| + ) | ||
| + | ||
| + if not allowed: | ||
| + raise AuthError(403, "You are allowed to see their presence.") |
|
|
|
LGTM |
erikjohnston
added a commit
that referenced
this pull request
Feb 19, 2016
erikjohnston
merged commit e5ad2e5
into
develop
Feb 19, 2016
1 check passed
default
Build finished. 323 tests run, 0 skipped, 0 failed.
Details
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
erikjohnston commentedFeb 17, 2016
m.presencelast_active_agotime remains below 1 minute, don't send updates to client. This is done by including acurrently_activeboolean field that when true indicates that clients should assume the user is only and active until further notice (i.e., their "last active" should be "now"). Clients will receive a new presence event when users stop being active.TODO: