File tree 2 files changed +18
-5
lines changed
2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 5
5
6
6
from database .collections import mongodb_connection
7
7
from routes .movies import movies_router
8
- from utils import initialize_db_movies_collection_from_dataset
8
+ from utils import is_db_movies_collection_initialized , initialize_db_movies_collection_from_dataset
9
9
10
10
11
11
logger = logging .getLogger ("uvicorn" )
@@ -17,11 +17,14 @@ def app_startup_event_handler():
17
17
"""
18
18
logger .info ('Initializing Movies collection from dataset ...' )
19
19
20
- start_time = time .time ()
21
- movies_inserted = initialize_db_movies_collection_from_dataset ()
20
+ if is_db_movies_collection_initialized ():
21
+ logger .info ('Collection already initialized' )
22
+ else :
23
+ start_time = time .time ()
24
+ movies_inserted = initialize_db_movies_collection_from_dataset ()
22
25
23
- logger .info (f'Successfully initialized the collection with { movies_inserted } movies, '
24
- f'elapsed time: { time .time () - start_time :.2f} seconds' )
26
+ logger .info (f'Successfully initialized the collection with { movies_inserted } movies, '
27
+ f'elapsed time: { time .time () - start_time :.2f} seconds' )
25
28
26
29
27
30
def app_shutdown_event_handler ():
Original file line number Diff line number Diff line change 8
8
from language_model import embedding_model
9
9
10
10
11
+ def is_db_movies_collection_initialized () -> bool :
12
+ """
13
+ Checks if the Movies collection is initialized.\n
14
+ For the sake of simplicity, collection is considered as initialized if it contains documents.
15
+
16
+ :return: True/False
17
+ """
18
+ return db_movies_collection .count_documents ({}) > 0
19
+
20
+
11
21
def initialize_db_movies_collection_from_dataset () -> int :
12
22
"""
13
23
Initialize Movies collection using TMDB 5000 Movie Dataset from Kaggle (https://www.kaggle.com/datasets/tmdb/tmdb-movie-metadata)\n
You can’t perform that action at this time.
0 commit comments