mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
people.js: Change functions to return a list of ids instead of objects.
The get_active_humans and get_non_active_humans functions used to return a list of user objects. The get_active_humans is used on settings_users.js and settings_bots.js, and in both places the only attributes needed of the person object are the user_id and full_name. To make the function return smaller, instead of a list of active humans, we are returning a list of active human ids, saving memory. With the ids we can call the people API to get the full_name attribute.
This commit is contained in:
committed by
Steve Howell
parent
99bed7b702
commit
e1e755c887
@@ -208,7 +208,7 @@ run_test('basics', () => {
|
||||
|
||||
realm_persons = people.get_realm_users();
|
||||
assert.equal(realm_persons.length, 1);
|
||||
assert.equal(people.get_active_human_count(), 1);
|
||||
assert.equal(people.get_active_human_ids().length, 1);
|
||||
|
||||
const full_name = 'Isaac Newton';
|
||||
const email = 'isaac@example.com';
|
||||
@@ -251,7 +251,7 @@ run_test('basics', () => {
|
||||
people.deactivate(isaac);
|
||||
person = people.get_active_user_for_email(email);
|
||||
assert(!person);
|
||||
assert.equal(people.get_non_active_humans().length, 1);
|
||||
assert.equal(people.get_non_active_human_ids().length, 1);
|
||||
assert.equal(people.get_active_human_count(), 1);
|
||||
assert.equal(people.is_active_user_for_popover(isaac.user_id), false);
|
||||
assert.equal(people.is_valid_email_for_compose(isaac.email), false);
|
||||
@@ -310,11 +310,11 @@ run_test('basics', () => {
|
||||
|
||||
// Reactivating issac
|
||||
people.add_active_user(isaac);
|
||||
const active_humans = people.get_active_humans();
|
||||
const active_humans = people.get_active_human_ids();
|
||||
assert.equal(active_humans.length, 2);
|
||||
assert.deepEqual(
|
||||
active_humans.sort((p) => p.user_id),
|
||||
[me, isaac]);
|
||||
[me.user_id, isaac.user_id]);
|
||||
});
|
||||
|
||||
run_test('check_active_non_active_users', () => {
|
||||
|
||||
@@ -723,28 +723,28 @@ exports.get_realm_users = function () {
|
||||
return Array.from(active_user_dict.values());
|
||||
};
|
||||
|
||||
exports.get_active_humans = function () {
|
||||
const humans = [];
|
||||
exports.get_active_human_ids = function () {
|
||||
const human_ids = [];
|
||||
|
||||
for (const user of active_user_dict.values()) {
|
||||
if (!user.is_bot) {
|
||||
humans.push(user);
|
||||
human_ids.push(user.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
return humans;
|
||||
return human_ids;
|
||||
};
|
||||
|
||||
exports.get_non_active_humans = function () {
|
||||
const humans = [];
|
||||
exports.get_non_active_human_ids = function () {
|
||||
const human_ids = [];
|
||||
|
||||
for (const user of non_active_user_dict.values()) {
|
||||
if (!user.is_bot) {
|
||||
humans.push(user);
|
||||
human_ids.push(user.user_id);
|
||||
}
|
||||
}
|
||||
|
||||
return humans;
|
||||
return human_ids;
|
||||
};
|
||||
|
||||
exports.get_active_human_count = function () {
|
||||
|
||||
@@ -391,7 +391,12 @@ exports.set_up = function () {
|
||||
const li = $(e.currentTarget).closest('li');
|
||||
const bot_id = parseInt(li.find('.bot_info').attr('data-user-id'), 10);
|
||||
const bot = bot_data.get(bot_id);
|
||||
const users_list = people.get_active_humans();
|
||||
const user_ids = people.get_active_human_ids();
|
||||
const users_list = user_ids.map(user_id => ({
|
||||
name: people.get_full_name(user_id),
|
||||
value: user_id.toString(),
|
||||
}));
|
||||
|
||||
$("#edit_bot_modal").empty();
|
||||
$("#edit_bot_modal").append(render_edit_bot({
|
||||
bot: bot,
|
||||
@@ -404,7 +409,7 @@ exports.set_up = function () {
|
||||
|
||||
const opts = {
|
||||
widget_name: 'bot_owner',
|
||||
data: users_list.map(u => ({name: u.full_name, value: u.user_id.toString()})),
|
||||
data: users_list,
|
||||
default_text: i18n.t("No owner"),
|
||||
value: bot.owner_id,
|
||||
};
|
||||
|
||||
@@ -464,10 +464,14 @@ function open_bot_form(person) {
|
||||
// NOTE: building `owner_dropdown` is quite expensive!
|
||||
const owner_id = bot_data.get(person.user_id).owner_id;
|
||||
|
||||
const users_list = people.get_active_humans();
|
||||
const user_ids = people.get_active_human_ids();
|
||||
const users_list = user_ids.map(user_id => ({
|
||||
name: people.get_full_name(user_id),
|
||||
value: user_id.toString(),
|
||||
}));
|
||||
const opts = {
|
||||
widget_name: 'edit_bot_owner',
|
||||
data: users_list.map(u => ({name: u.full_name, value: u.user_id.toString()})),
|
||||
data: users_list,
|
||||
default_text: i18n.t("No owner"),
|
||||
value: owner_id,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user