Made it so that BGG request can no longer spam
This commit is contained in:
parent
0529819da8
commit
18fb6a38b3
2 changed files with 81 additions and 72 deletions
|
|
@ -175,7 +175,8 @@ def convert_collection_xml_to_wishlist_boardgame(boardgame_extra_info: boardgame
|
|||
wishlist_priority = collection_boardgame_xml.find('status').get('wishlistpriority')
|
||||
|
||||
wishlist_boardgame_dict = {
|
||||
"wishlist_priority" : wishlist_priority,
|
||||
"boardgame_id" : boardgame_extra_info.id,
|
||||
"wishlist_priority" : wishlist_priority
|
||||
}
|
||||
|
||||
wishlist_info = boardgame_classes.WishlistInfo.model_validate(wishlist_boardgame_dict)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ def get_db_engine():
|
|||
def get_boardgame(session: Session, boardgame_id: int) -> boardgame_classes.BoardGame:
|
||||
#Will check if it already exists in db, then it will get it from there
|
||||
|
||||
|
||||
with critical_function_lock:
|
||||
boardgame_in_db = db_connection.get_boardgame(session, boardgame_id=boardgame_id)
|
||||
|
||||
to_return_boardgame = None
|
||||
|
|
@ -29,6 +31,8 @@ def get_boardgame(session: Session, boardgame_id: int) -> boardgame_classes.Boar
|
|||
|
||||
|
||||
def get_multiple_boardgames(session: Session, boardgame_ids: list[int]) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
with critical_function_lock:
|
||||
boardgames_in_db, boardgame_ids_missing = db_connection.get_multiple_boardgames(session, boardgame_ids=boardgame_ids)
|
||||
|
||||
if len(boardgame_ids_missing) != 0:
|
||||
|
|
@ -40,6 +44,8 @@ def get_multiple_boardgames(session: Session, boardgame_ids: list[int]) -> list[
|
|||
return boardgames_in_db
|
||||
|
||||
def get_user_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
with critical_function_lock:
|
||||
boardgames_from_db: list[boardgame_classes.BoardGame] = db_connection.get_all_boardgames(session)
|
||||
|
||||
if len(boardgames_from_db) == 0:
|
||||
|
|
@ -53,6 +59,7 @@ def get_user_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
|||
|
||||
def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
with critical_function_lock:
|
||||
owned_boardgames_from_db = db_connection.get_owned_boardgames(session)
|
||||
|
||||
if len(owned_boardgames_from_db) == 0:
|
||||
|
|
@ -66,6 +73,7 @@ def get_user_owned_collection(session: Session) -> list[boardgame_classes.BoardG
|
|||
|
||||
def get_user_wishlist_collection(session: Session, wishlist_priority: int = 0) -> list[boardgame_classes.BoardGame]:
|
||||
|
||||
with critical_function_lock:
|
||||
wishlisted_boardgames_from_db = db_connection.get_wishlist_boardgames(session)
|
||||
|
||||
if len(wishlisted_boardgames_from_db) == 0:
|
||||
|
|
@ -74,7 +82,6 @@ def get_user_wishlist_collection(session: Session, wishlist_priority: int = 0) -
|
|||
|
||||
wishlisted_boardgames_from_db = db_connection.get_wishlist_boardgames(session)
|
||||
|
||||
print(wishlisted_boardgames_from_db)
|
||||
if wishlist_priority != 0:
|
||||
wishlisted_boardgames_from_db = list(filter(lambda game: game.wishlist_info.wishlist_priority == wishlist_priority, wishlisted_boardgames_from_db))
|
||||
|
||||
|
|
@ -83,6 +90,7 @@ def get_user_wishlist_collection(session: Session, wishlist_priority: int = 0) -
|
|||
|
||||
def get_plays(session: Session) -> list[play_classes.Play]:
|
||||
|
||||
with critical_function_lock:
|
||||
plays_from_db = db_connection.get_plays(session)
|
||||
|
||||
if len(plays_from_db) == 0:
|
||||
|
|
@ -101,12 +109,11 @@ def get_plays(session: Session) -> list[play_classes.Play]:
|
|||
|
||||
assert len(list(filter(lambda x: x == None, played_boardgame_ids))) == 0, plays_from_db
|
||||
|
||||
#Make sure to add all board games that are played
|
||||
get_multiple_boardgames(session, played_boardgame_ids)
|
||||
|
||||
return plays_from_db
|
||||
|
||||
def get_players_from_play(session: Session, play_id: int) -> list[play_classes.PlayPlayer]:
|
||||
|
||||
with critical_function_lock:
|
||||
players_from_db = db_connection.get_players_from_play(session, play_id)
|
||||
|
||||
if len(players_from_db) == 0:
|
||||
|
|
@ -119,6 +126,7 @@ def get_players_from_play(session: Session, play_id: int) -> list[play_classes.P
|
|||
return players_from_db
|
||||
|
||||
def get_all_players(session: Session) -> list[player_classes.Player]:
|
||||
with critical_function_lock:
|
||||
players_from_db = db_connection.get_all_players(session)
|
||||
|
||||
if len(players_from_db) == 0:
|
||||
|
|
|
|||
Loading…
Reference in a new issue