1
This commit is contained in:
parent
6a95fa1365
commit
133cfec9dd
@ -91,21 +91,6 @@ def _refreshData(row, data_list, data_info):
|
|||||||
if (len(data_list) > 50):
|
if (len(data_list) > 50):
|
||||||
del data_list[50:]
|
del data_list[50:]
|
||||||
|
|
||||||
#更新排行榜
|
|
||||||
def _updateKillRank(r, channel, kill_list):
|
|
||||||
kill_list.sort(key=take_kills, reverse=True)
|
|
||||||
kill_rank = []
|
|
||||||
for kill_index in range(min(50, len(kill_list))):
|
|
||||||
kill_rank.append(kill_list[kill_index])
|
|
||||||
r.set("game2005api:kill_rank_" + channel, json.dumps(kill_rank))
|
|
||||||
|
|
||||||
def _updateWinRank(r, channel, win_list):
|
|
||||||
win_list.sort(key=take_game_times, reverse=True)
|
|
||||||
win_rank = []
|
|
||||||
for win_index in range(min(50, len(win_list))):
|
|
||||||
win_rank.append(win_list[win_index])
|
|
||||||
r.set("game2005api:win_rank_" + channel, json.dumps(win_rank))
|
|
||||||
|
|
||||||
def _updateScoreRank(r, channel, integral_list):
|
def _updateScoreRank(r, channel, integral_list):
|
||||||
integral_list.sort(key=take_integral_times, reverse=True)
|
integral_list.sort(key=take_integral_times, reverse=True)
|
||||||
integral_rank = []
|
integral_rank = []
|
||||||
@ -116,8 +101,6 @@ def _updateScoreRank(r, channel, integral_list):
|
|||||||
def fullUpdateRank():
|
def fullUpdateRank():
|
||||||
f7.udplog.info('fullUpdateRank begin')
|
f7.udplog.info('fullUpdateRank begin')
|
||||||
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
||||||
kill_hash = {}
|
|
||||||
win_hash = {}
|
|
||||||
integral_hash = {}
|
integral_hash = {}
|
||||||
for conf in mysql_conf:
|
for conf in mysql_conf:
|
||||||
conn = pymysql.connect(host = conf['host'],
|
conn = pymysql.connect(host = conf['host'],
|
||||||
@ -132,22 +115,11 @@ def fullUpdateRank():
|
|||||||
temp_idx = 0
|
temp_idx = 0
|
||||||
while 1:
|
while 1:
|
||||||
cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,'
|
cursor.execute('SELECT accountid, user_name, avatar_url, kills, alive_time,'
|
||||||
' harm, win_times, game_times, idx, integral, season_time FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx))
|
' harm, win_times, game_times, idx, integral, season_time '
|
||||||
|
'FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx))
|
||||||
has_data = False
|
has_data = False
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
has_data = True
|
has_data = True
|
||||||
#更新击杀榜
|
|
||||||
channel = f7.getChannelByAccountId(row[0])
|
|
||||||
if checkchannel(channel):
|
|
||||||
if channel not in kill_hash:
|
|
||||||
kill_hash[channel] = []
|
|
||||||
_refreshData(row, kill_hash[channel], take_kills)
|
|
||||||
#更新胜场榜
|
|
||||||
channel = f7.getChannelByAccountId(row[0])
|
|
||||||
if checkchannel(channel):
|
|
||||||
if channel not in win_hash:
|
|
||||||
win_hash[channel] = []
|
|
||||||
_refreshData(row, win_hash[channel], take_game_times)
|
|
||||||
#更新积分榜
|
#更新积分榜
|
||||||
channel = f7.getChannelByAccountId(row[0])
|
channel = f7.getChannelByAccountId(row[0])
|
||||||
if checkchannel(channel):
|
if checkchannel(channel):
|
||||||
@ -163,10 +135,6 @@ def fullUpdateRank():
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
r = _getRedis()
|
r = _getRedis()
|
||||||
for channel in kill_hash:
|
|
||||||
_updateKillRank(r, channel, kill_hash[channel])
|
|
||||||
for channel in win_hash:
|
|
||||||
_updateWinRank(r, channel, win_hash[channel])
|
|
||||||
for channel in integral_hash:
|
for channel in integral_hash:
|
||||||
_updateScoreRank(r, channel, integral_hash[channel])
|
_updateScoreRank(r, channel, integral_hash[channel])
|
||||||
f7.udplog.info('fullUpdateRank end')
|
f7.udplog.info('fullUpdateRank end')
|
||||||
@ -182,8 +150,6 @@ def _fullUpdateRank(rushtime):
|
|||||||
def incrementUpdateRank():
|
def incrementUpdateRank():
|
||||||
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
||||||
r = _getRedis()
|
r = _getRedis()
|
||||||
kill_hash = {}
|
|
||||||
win_hash = {}
|
|
||||||
integral_hash = {}
|
integral_hash = {}
|
||||||
for conf in mysql_conf:
|
for conf in mysql_conf:
|
||||||
conn = pymysql.connect(host = conf['host'],
|
conn = pymysql.connect(host = conf['host'],
|
||||||
@ -205,18 +171,6 @@ def incrementUpdateRank():
|
|||||||
has_data = True
|
has_data = True
|
||||||
channel = f7.getChannelByAccountId(row[0])
|
channel = f7.getChannelByAccountId(row[0])
|
||||||
if checkchannel(channel):
|
if checkchannel(channel):
|
||||||
#更新击杀榜
|
|
||||||
if channel not in kill_hash:
|
|
||||||
kill_list = r.get('game2005api:kill_rank_' + channel)
|
|
||||||
kill_hash[channel] = [] if not kill_list else json.loads(kill_list)
|
|
||||||
_delRepeatData(row, kill_hash[channel])
|
|
||||||
_refreshData(row, kill_hash[channel], take_kills)
|
|
||||||
#更新胜场榜
|
|
||||||
if channel not in win_hash:
|
|
||||||
win_list = r.get('game2005api:win_rank_' + channel)
|
|
||||||
win_hash[channel] = [] if not win_list else json.loads(win_list)
|
|
||||||
_delRepeatData(row, win_hash[channel])
|
|
||||||
_refreshData(row, win_hash[channel], take_game_times)
|
|
||||||
#更新积分榜
|
#更新积分榜
|
||||||
if channel not in integral_hash:
|
if channel not in integral_hash:
|
||||||
integral_list = r.get('game2005api:integral_rank_' + channel)
|
integral_list = r.get('game2005api:integral_rank_' + channel)
|
||||||
@ -231,15 +185,10 @@ def incrementUpdateRank():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
for channel in kill_hash:
|
|
||||||
_updateKillRank(r, channel, kill_hash[channel])
|
|
||||||
for channel in win_hash:
|
|
||||||
_updateWinRank(r, channel, win_hash[channel])
|
|
||||||
for channel in integral_hash:
|
for channel in integral_hash:
|
||||||
_updateScoreRank(r, channel, integral_hash[channel])
|
_updateScoreRank(r, channel, integral_hash[channel])
|
||||||
f7.udplog.info('incrementUpdateRank end')
|
f7.udplog.info('incrementUpdateRank end')
|
||||||
|
|
||||||
#每5分钟读取mysql里发生改变过的数据更新排行榜
|
|
||||||
def _incrementUpdateRank(rushtime):
|
def _incrementUpdateRank(rushtime):
|
||||||
def done_callback():
|
def done_callback():
|
||||||
f7.timer.callLater(rushtime,
|
f7.timer.callLater(rushtime,
|
||||||
|
@ -149,8 +149,8 @@ class UserController extends BaseAuthedController {
|
|||||||
'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0,
|
'last_season_id' => $currSeasonMeta ? $currSeasonMeta['id'] : 0,
|
||||||
'head_list' => json_encode($headList),
|
'head_list' => json_encode($headList),
|
||||||
'head_frame_list' => json_encode($headFrameList),
|
'head_frame_list' => json_encode($headFrameList),
|
||||||
'score_createtime' => $this->_getNowTime(),
|
'score_modifytime' => $this->_getNowTime(),
|
||||||
'best_rank_createtime' => $this->_getNowTime(),
|
'best_rank_modifytime' => $this->_getNowTime(),
|
||||||
'createtime' => $this->_getNowTime(),
|
'createtime' => $this->_getNowTime(),
|
||||||
'modifytime' => $this->_getNowTime(),
|
'modifytime' => $this->_getNowTime(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user