Delay fetching for all users for a faster load

This commit is contained in:
Jeremy Zhang 2018-08-20 19:43:12 +00:00
parent 3e27b156a8
commit 4672243ebe
2 changed files with 23 additions and 3 deletions

View File

@ -444,11 +444,10 @@ def process_query_guild(guild_id, visitor=False):
emojis = get_guild_emojis(guild_id)
roles = get_guild_roles(guild_id)
guest_icon = get_guild_guest_icon(guild_id)
all_users = get_all_users(guild_id)
if visitor:
for channel in channels:
channel["write"] = False
return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, allusers=all_users, emojis=emojis, roles=roles, guest_icon=guest_icon, instant_invite=widget.get("instant_invite", None))
return jsonify(channels=channels, discordmembers=discordmembers, embedmembers=embedmembers, emojis=emojis, roles=roles, guest_icon=guest_icon, instant_invite=widget.get("instant_invite", None))
@api.route("/query_guild", methods=["GET"])
@valid_session_required(api=True)
@ -534,6 +533,11 @@ def user_info(guild_id, user_id):
usr["badges"].append("discordbotsorgvoted")
return jsonify(usr)
@api.route("/user/<guild_id>")
def list_users(guild_id):
all_users = get_all_users(guild_id)
return jsonify(all_users)
@api.route("/webhook/discordbotsorg/vote", methods=["POST"])
def webhook_discordbotsorg_vote():
incoming = request.get_json()

View File

@ -194,6 +194,14 @@
return funct.promise();
}
function list_users() {
var funct = $.ajax({
dataType: "json",
url: "/api/user/" + guild_id,
});
return funct.promise();
}
function performLocalStorageTest() {
var test = 'test';
try {
@ -644,7 +652,6 @@
}
function prepare_guild(guildobj) {
all_users = guildobj.allusers;
global_guest_icon = guildobj.guest_icon;
emoji_store = guildobj.emojis;
update_emoji_picker();
@ -1793,6 +1800,12 @@
return;
}
lastWord = lastWord.substr(1);
if (all_users.length == 0) {
var usrs = list_users();
usrs.done(function (lst) {
all_users = lst;
});
}
var template = $('#mustache_usermentionchoices').html();
Mustache.parse(template);
var users = [];
@ -2115,6 +2128,9 @@
discord_users_list.push(usr);
fill_discord_members(discord_users_list);
}
if (all_users.length == 0) {
return;
}
all_users.push({
"id": usr.id,
"avatar": usr.avatar,