From 4672243ebe5c4991e6fdadbe652c81c146cf2dc6 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Mon, 20 Aug 2018 19:43:12 +0000 Subject: [PATCH] Delay fetching for all users for a faster load --- webapp/titanembeds/blueprints/api/api.py | 8 ++++++-- webapp/titanembeds/static/js/embed.js | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index 5e681fd..def41aa 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -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) @@ -533,6 +532,11 @@ def user_info(guild_id, user_id): if redis_store.get("DiscordBotsOrgVoted/" + str(member["id"])): usr["badges"].append("discordbotsorgvoted") return jsonify(usr) + +@api.route("/user/") +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(): diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 79bfad0..be09394 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -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,