diff --git a/dota.py b/dota.py index 6bc020d..13a80de 100644 --- a/dota.py +++ b/dota.py @@ -258,6 +258,15 @@ def get_friends_recent_matches(): for friend in Friend.filter(active=True): 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(): logger.info('create match, match info: %s' % match_.__dict__) match_obj = Match.create( @@ -267,15 +276,6 @@ def get_friends_recent_matches(): radiant_win=match_.radiant_win, 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()) return matches