mirror of
https://github.com/Viren070/MediaFusion.git
synced 2025-12-01 23:21:11 +01:00
03297f2b22
Update Crud functions for new database structure & utlize 10x performance in the catalog data fetchers with new db structure and mongodb indexes. Added support for multi season pack torrents, Updated metadata handling to use a centralized fetching mechanism and improved filters for matching existing entries. Refactored episode processing logic to account for season and episode numbers more flexibly. Enhanced querying pipelines for better performance in catalog and metadata retrieval.
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from beanie import init_beanie
|
|
|
|
from db.config import settings
|
|
from db.models import (
|
|
MediaFusionSeriesMetaData,
|
|
MediaFusionMovieMetaData,
|
|
TorrentStreams,
|
|
TVStreams,
|
|
MediaFusionTVMetaData,
|
|
)
|
|
|
|
logging.getLogger("pymongo").setLevel(logging.WARNING)
|
|
|
|
|
|
async def init(allow_index_dropping: bool = False):
|
|
retries = 5
|
|
for i in range(retries):
|
|
try:
|
|
# Create a Motor client with maxPoolSize
|
|
client = AsyncIOMotorClient(
|
|
settings.mongo_uri, maxPoolSize=settings.db_max_connections
|
|
)
|
|
# Init beanie with the Product document class
|
|
await init_beanie(
|
|
database=client.get_default_database(), # Note that the database needs to be passed as part of the URI
|
|
document_models=[
|
|
MediaFusionMovieMetaData,
|
|
MediaFusionSeriesMetaData,
|
|
MediaFusionTVMetaData,
|
|
TorrentStreams,
|
|
TVStreams,
|
|
],
|
|
multiprocessing_mode=True,
|
|
allow_index_dropping=allow_index_dropping,
|
|
)
|
|
logging.info("Database initialized successfully.")
|
|
break
|
|
except Exception as e:
|
|
if i < retries - 1: # i is zero indexed
|
|
wait_time = 2**i # exponential backoff
|
|
logging.exception(
|
|
f"Error initializing database: {e}, retrying in {wait_time} seconds..."
|
|
)
|
|
await asyncio.sleep(wait_time)
|
|
else:
|
|
logging.error("Failed to initialize database after several attempts.")
|
|
raise e
|