Commit c4395e62 authored by nanahira's avatar nanahira

add challonge cache

parent 9ebbb587
......@@ -306,10 +306,24 @@ if settings.modules.challonge.enabled
is_requesting[1] = true
challonge.matches.index(_data)
return
setInterval(
refresh_challonge_cache = () ->
challonge_cache[0] = null
challonge_cache[1] = null
, 10000)
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: (() ->
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: (() ->
return
)
})
return
)
})
return
refresh_challonge_cache()
setInterval(refresh_challonge_cache, 30000)
# 获取可用内存
memory_usage = 0
......@@ -987,7 +1001,7 @@ class Room
if err
log.warn("Errored pushing scores to Challonge.", err)
else
challonge_cache[1] = null
refresh_challonge_cache()
return
})
if @player_datas.length and settings.modules.cloud_replay.enabled
......@@ -2858,7 +2872,7 @@ ygopro.stoc_follow 'CHANGE_SIDE', false, (buffer, info, client, server)->
if err
log.warn("Errored pushing scores to Challonge.", err)
else
challonge_cache[1] = null
refresh_challonge_cache()
return
})
if room.random_type or room.arena
......
// Generated by CoffeeScript 1.12.7
(function() {
var CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, _, addCallback, badwords, ban_user, bunyan, challonge, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_memory_usage, http, http_server, https, https_server, import_datas, imported, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_looplimit, windbots, ygopro, zlib;
var CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, Cloud_replay_ids, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_players_banned, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, Room, SERVER_clear_disconnect, _, addCallback, badwords, ban_user, bunyan, challonge, challonge_cache, challonge_queue_callbacks, chat_color, config, cppversion, crypto, date, default_config, default_data, dialogues, disconnect_list, duel_log, e, exec, execFile, fs, geoip, get_callback, get_memory_usage, http, http_server, https, https_server, import_datas, imported, is_requesting, j, l, len, len1, lflists, list, loadJSON, load_dialogues, load_tips, log, long_resolve_cards, memory_usage, merge, moment, net, oldbadwords, oldconfig, olddialogues, oldduellog, oldtips, options, os, path, pgClient, pg_client, pg_query, redis, redisdb, ref, ref1, refresh_challonge_cache, release_disconnect, report_to_big_brother, request, requestListener, roomlist, setting_change, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, url, users_cache, wait_room_start, wait_room_start_arena, windbot_looplimit, windbots, ygopro, zlib;
net = require('net');
......@@ -318,6 +318,61 @@
challonge = require('challonge').createClient({
apiKey: settings.modules.challonge.api_key
});
challonge_cache = [];
challonge_queue_callbacks = [[], []];
is_requesting = [false, false];
get_callback = function(challonge_type, _callback) {
return (function(err, data) {
var cur_callback;
if (!err && data) {
challonge_cache[challonge_type] = data;
}
_callback(err, data);
while (challonge_queue_callbacks[challonge_type].length) {
cur_callback = challonge_queue_callbacks[challonge_type][0];
challonge_queue_callbacks[challonge_type].splice(0, 1);
cur_callback(err, data);
}
is_requesting[challonge_type] = false;
});
};
challonge.participants._index = function(_data) {
if (challonge_cache[0]) {
_data.callback(null, challonge_cache[0]);
} else if (is_requesting[0]) {
challonge_queue_callbacks[0].push(_data.callback);
} else {
_data.callback = get_callback(0, _data.callback);
is_requesting[0] = true;
challonge.participants.index(_data);
}
};
challonge.matches._index = function(_data) {
if (challonge_cache[1]) {
_data.callback(null, challonge_cache[1]);
} else if (is_requesting[1]) {
challonge_queue_callbacks[1].push(_data.callback);
} else {
_data.callback = get_callback(1, _data.callback);
is_requesting[1] = true;
challonge.matches.index(_data);
}
};
refresh_challonge_cache = function() {
challonge_cache[0] = null;
challonge_cache[1] = null;
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: (function() {
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: (function() {})
});
})
});
};
refresh_challonge_cache();
setInterval(refresh_challonge_cache, 30000);
}
memory_usage = 0;
......@@ -1223,6 +1278,8 @@
callback: function(err, data) {
if (err) {
log.warn("Errored pushing scores to Challonge.", err);
} else {
refresh_challonge_cache();
}
}
});
......@@ -2008,7 +2065,7 @@
}
} else {
ygopro.stoc_send_chat(client, '${loading_user_info}', ygopro.constants.COLORS.BABYBLUE);
challonge.participants.index({
challonge.participants._index({
id: settings.modules.challonge.tournament_id,
callback: function(err, data) {
var found, k, user;
......@@ -2032,7 +2089,7 @@
return;
}
client.challonge_info = found;
challonge.matches.index({
challonge.matches._index({
id: settings.modules.challonge.tournament_id,
callback: function(err, data) {
var len4, len5, match, o, p, player, ref4, ref5;
......@@ -3552,6 +3609,8 @@
callback: function(err, data) {
if (err) {
log.warn("Errored pushing scores to Challonge.", err);
} else {
refresh_challonge_cache();
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment