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) emojis = get_guild_emojis(guild_id)
roles = get_guild_roles(guild_id) roles = get_guild_roles(guild_id)
guest_icon = get_guild_guest_icon(guild_id) guest_icon = get_guild_guest_icon(guild_id)
all_users = get_all_users(guild_id)
if visitor: if visitor:
for channel in channels: for channel in channels:
channel["write"] = False 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"]) @api.route("/query_guild", methods=["GET"])
@valid_session_required(api=True) @valid_session_required(api=True)
@ -533,6 +532,11 @@ def user_info(guild_id, user_id):
if redis_store.get("DiscordBotsOrgVoted/" + str(member["id"])): if redis_store.get("DiscordBotsOrgVoted/" + str(member["id"])):
usr["badges"].append("discordbotsorgvoted") usr["badges"].append("discordbotsorgvoted")
return jsonify(usr) 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"]) @api.route("/webhook/discordbotsorg/vote", methods=["POST"])
def webhook_discordbotsorg_vote(): def webhook_discordbotsorg_vote():

View File

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