This commit is contained in:
27
main.py
27
main.py
@@ -22,7 +22,7 @@ from auth.oauth import oauth_callback, oauth_login
|
||||
from cache.precache import precache_data
|
||||
from cache.revalidator import revalidation_manager
|
||||
from rbac import initialize_rbac
|
||||
from services.search import check_search_service, search_service
|
||||
from services.search import check_search_service, initialize_search_index, search_service
|
||||
from services.viewed import ViewedStorage
|
||||
from settings import DEV_SERVER_PID_FILE_NAME
|
||||
from storage.redis import redis
|
||||
@@ -194,6 +194,26 @@ async def dev_start() -> None:
|
||||
print(f"[warning] Error during DEV mode initialization: {e!s}")
|
||||
|
||||
|
||||
async def initialize_search_index_with_data() -> None:
|
||||
"""Инициализация поискового индекса данными из БД"""
|
||||
try:
|
||||
from orm.shout import Shout
|
||||
from storage.db import local_session
|
||||
|
||||
# Получаем все опубликованные шауты из БД
|
||||
with local_session() as session:
|
||||
shouts = session.query(Shout).filter(Shout.published_at.is_not(None)).all()
|
||||
|
||||
if shouts:
|
||||
await initialize_search_index(shouts)
|
||||
print(f"[search] Loaded {len(shouts)} published shouts into search index")
|
||||
else:
|
||||
print("[search] No published shouts found to index")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to initialize search index with data: {e}")
|
||||
|
||||
|
||||
# Глобальная переменная для background tasks
|
||||
background_tasks: list[asyncio.Task] = []
|
||||
|
||||
@@ -236,8 +256,9 @@ async def lifespan(app: Starlette):
|
||||
await dev_start()
|
||||
print("[lifespan] Basic initialization complete")
|
||||
|
||||
# Search service is now handled by Muvera automatically
|
||||
# No need for background indexing tasks
|
||||
# Инициализируем поисковый индекс данными из БД
|
||||
print("[lifespan] Initializing search index with existing data...")
|
||||
await initialize_search_index_with_data()
|
||||
print("[lifespan] Search service initialized with Muvera")
|
||||
|
||||
yield
|
||||
|
||||
Reference in New Issue
Block a user