feat: Optimize match processing by updating streaks before creating database records
This commit is contained in:
parent
b5c58f842a
commit
895737927a
18
dota.py
18
dota.py
@ -258,6 +258,15 @@ def get_friends_recent_matches():
|
|||||||
|
|
||||||
for friend in Friend.filter(active=True):
|
for friend in Friend.filter(active=True):
|
||||||
for match_ in friend.get_recent_matches():
|
for match_ in friend.get_recent_matches():
|
||||||
|
# 判断玩家是否获胜
|
||||||
|
player_won = match_.radiant_win == (match_.player_slot < 128)
|
||||||
|
|
||||||
|
# 总是尝试更新连胜连败(update_streak内部会检查是否重复)
|
||||||
|
streak_info = friend.update_streak(match_.match_id, player_won)
|
||||||
|
if streak_info:
|
||||||
|
streak_updates.append(streak_info)
|
||||||
|
|
||||||
|
# 只有新比赛才创建数据库记录和返回结果
|
||||||
if not Match.select().where(Match.match_id == match_.match_id).exists():
|
if not Match.select().where(Match.match_id == match_.match_id).exists():
|
||||||
logger.info('create match, match info: %s' % match_.__dict__)
|
logger.info('create match, match info: %s' % match_.__dict__)
|
||||||
match_obj = Match.create(
|
match_obj = Match.create(
|
||||||
@ -267,15 +276,6 @@ def get_friends_recent_matches():
|
|||||||
radiant_win=match_.radiant_win,
|
radiant_win=match_.radiant_win,
|
||||||
party_size=match_.party_size,
|
party_size=match_.party_size,
|
||||||
)
|
)
|
||||||
|
|
||||||
# 判断玩家是否获胜
|
|
||||||
player_won = match_.radiant_win == (match_.player_slot < 128)
|
|
||||||
|
|
||||||
# 更新连胜连败
|
|
||||||
streak_info = friend.update_streak(match_.match_id, player_won)
|
|
||||||
if streak_info:
|
|
||||||
streak_updates.append(streak_info)
|
|
||||||
|
|
||||||
matches.append(match_obj.serialize_match())
|
matches.append(match_obj.serialize_match())
|
||||||
|
|
||||||
return matches
|
return matches
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user