File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ def keep_connection_alive():
5353
5454def setup_database_indexes ():
5555 """Set up MongoDB indexes for optimal query performance"""
56+ from pymongo .errors import DuplicateKeyError , OperationFailure
57+
5658 try :
5759 game_collection = db ["game" ]
5860
@@ -66,20 +68,24 @@ def setup_database_indexes():
6668
6769 # Index for sorting operations
6870 game_collection .create_index ([("date" , - 1 )], background = True )
69-
70- # Index to have unique games so we won't add duplicates
71- game_collection .create_index (
72- [
73- ("sport" , 1 ),
74- ("gender" , 1 ),
75- ("date" , 1 ),
76- ("opponent_id" , 1 ),
77- ("state" , 1 ),
78- ],
79- unique = True ,
80- background = True
81- )
82-
71+
72+ try :
73+ game_collection .create_index (
74+ [
75+ ("sport" , 1 ),
76+ ("gender" , 1 ),
77+ ("date" , 1 ),
78+ ("opponent_id" , 1 ),
79+ ("city" , 1 ),
80+ ("state" , 1 ),
81+ ("location" , 1 ),
82+ ],
83+ unique = True ,
84+ background = True
85+ )
86+ except (DuplicateKeyError , OperationFailure ) as e :
87+ print (f"Warning: Could not create unique index due to existing duplicates: { e } " )
88+
8389 # Additional index for tournament games (without opponent_id)
8490 game_collection .create_index (
8591 [
You can’t perform that action at this time.
0 commit comments