Skip to content

Commit cd1949f

Browse files
Adding more detailed logging
1 parent dabad11 commit cd1949f

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
if use_tls:
1919
# client_options = {
2020
# "maxPoolSize": 100,
21+
# "minPoolSize": 10,
2122
# "waitQueueTimeoutMS": 2000,
2223
# "connectTimeoutMS": 30000,
2324
# "socketTimeoutMS": 45000,
25+
# "serverSelectionTimeoutMS": 30000
2426
# }
2527
client = MongoClient(
2628
os.getenv("MONGO_URI"),

src/repositories/game_repository.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
from src.database import db
22
from src.models.game import Game
33

4+
import threading
5+
import logging
6+
7+
# Configure logging
8+
logging.basicConfig(
9+
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
10+
)
11+
logger = logging.getLogger(__name__)
12+
413

514
class GameRepository:
615
@staticmethod
716
def find_all(limit=100, offset=0):
817
"""
9-
Retrieve all games from the 'games' collection in MongoDB with pagination.
18+
Retrieve all games from the 'game' collection in MongoDB with pagination.
19+
"""
20+
request_id = id(threading.current_thread()) # Get a unique ID for this request
21+
logger.info(
22+
f"Request {request_id}: Starting find_all with limit={limit}, offset={offset}"
23+
)
1024

11-
Args:
12-
limit (int): Maximum number of records to return
13-
offset (int): Number of records to skip
25+
try:
26+
game_collection = db["game"]
27+
logger.info(f"Request {request_id}: Connected to game collection")
1428

15-
Returns:
16-
List[Game]: A list of Game objects.
17-
"""
18-
game_collection = db["game"]
19-
games = game_collection.find().skip(offset).limit(limit)
20-
return [Game.from_dict(game) for game in games]
29+
cursor = game_collection.find().skip(offset).limit(limit)
30+
logger.info(f"Request {request_id}: Created cursor")
31+
32+
# Force MongoDB to actually perform the query
33+
games_list = list(cursor)
34+
logger.info(f"Request {request_id}: Retrieved {len(games_list)} games")
35+
36+
result = [Game.from_dict(game) for game in games_list]
37+
logger.info(
38+
f"Request {request_id}: Converted to {len(result)} Game objects"
39+
)
40+
41+
return result
42+
except Exception as e:
43+
logger.error(f"Request {request_id}: Error in find_all: {str(e)}")
44+
raise
2145

2246
@staticmethod
2347
def find_by_id(game_id):

0 commit comments

Comments
 (0)