Skip to content

Commit

Permalink
Check if game exists before creation
Browse files Browse the repository at this point in the history
  • Loading branch information
henworth committed Sep 11, 2021
1 parent b7a5989 commit 7b2dae5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions seraphsix/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ async def get_clan_members_inactive(self, clan_db, **kwargs):
).prefetch_related("member")

async def create_game(self, game):
game_db = await Game.create(**vars(game))
log.info(f"Game {game_db.instance_id} created")
return game_db
retval = None
game_db, is_created = await Game.get_or_create(**vars(game))
if is_created:
log.info(f"Game {game.instance_id} created")
retval = game_db
return retval

async def create_clan_game(self, game_db, game, clan_id):
data = dict(clan_id=clan_id, game=game_db)
Expand Down
2 changes: 1 addition & 1 deletion seraphsix/tasks/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async def process_activity(ctx, activity, guild_id, guild_name, player_check=Fal

game_db = await database.create_game(clan_game)
if not game_db:
log.error(f"Continuing because error with storing game {game.instance_id}")
log.debug(f"Continuing because error with storing game {game.instance_id}")
return

await database.create_clan_game(game_db, clan_game, clan_game.clan_id)
Expand Down

0 comments on commit 7b2dae5

Please sign in to comment.