Set initial user presences in O(n), not O(n²) time

Previous code iteratively called set_user_status() once for each user;
which in turn was rerendering the user sidebar, also once for each user.

I changed the API a bit by replacing activity.set_user_status() with
activity.set_user_statuses(), plural, that takes an object and updates
all the user statuses in one go before rendering.

(imported from commit 1111c9029264f892f25e76d2e5e5ff996dcbc7ca)
This commit is contained in:
Scott Feeney
2013-07-11 15:51:26 -04:00
parent 8fcf208815
commit 4313f2ff1e
2 changed files with 20 additions and 10 deletions

View File

@@ -72,10 +72,8 @@ $(function () {
"full_name": "Humbug Feedback Bot"});
}
$.each(page_params.initial_presences, function (email, presence) {
activity.set_user_status(email, presence, page_params.initial_servertime);
});
activity.set_user_statuses(page_params.initial_presences,
page_params.initial_servertime);
});
function within_viewport(row_offset, row_height) {
@@ -823,7 +821,9 @@ function get_updates_success(data) {
}
break;
case 'presence':
activity.set_user_status(event.email, event.presence, event.server_timestamp);
var users = {};
users[event.email] = event.presence;
activity.set_user_statuses(users, event.server_timestamp);
break;
}
});