fix: stabilize backend services and frontend pointer
This commit is contained in:
@@ -54,6 +54,8 @@ class RagChatServiceImpl(IRagChatService):
|
||||
_task_done: dict[str, bool] = {}
|
||||
_task_locks: dict[str, asyncio.Lock] = {}
|
||||
_title_tasks: dict[str, asyncio.Task] = {}
|
||||
_chat_schema_checked = False
|
||||
_chat_schema_lock = asyncio.Lock()
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.TenantResolver = TenantResolver()
|
||||
@@ -731,8 +733,34 @@ class RagChatServiceImpl(IRagChatService):
|
||||
)
|
||||
|
||||
async def _ensure_rag_chat_schema(self, session) -> None:
|
||||
await session.execute(text("ALTER TABLE rag_chat_app ADD COLUMN IF NOT EXISTS tenant_code VARCHAR(64) NULL"))
|
||||
await session.execute(text("CREATE INDEX IF NOT EXISTS idx_rag_chat_app_tenant_code ON rag_chat_app(tenant_code) WHERE deleted_at IS NULL"))
|
||||
if self.__class__._chat_schema_checked:
|
||||
return
|
||||
|
||||
async with self.__class__._chat_schema_lock:
|
||||
if self.__class__._chat_schema_checked:
|
||||
return
|
||||
|
||||
exists = (
|
||||
await session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = current_schema()
|
||||
AND table_name = 'rag_chat_app'
|
||||
AND column_name = 'tenant_code'
|
||||
"""
|
||||
)
|
||||
)
|
||||
).scalar_one_or_none()
|
||||
if exists:
|
||||
self.__class__._chat_schema_checked = True
|
||||
return
|
||||
|
||||
await session.execute(text("SET LOCAL lock_timeout = '1000ms'"))
|
||||
await session.execute(text("ALTER TABLE rag_chat_app ADD COLUMN tenant_code VARCHAR(64) NULL"))
|
||||
await session.execute(text("CREATE INDEX IF NOT EXISTS idx_rag_chat_app_tenant_code ON rag_chat_app(tenant_code) WHERE deleted_at IS NULL"))
|
||||
self.__class__._chat_schema_checked = True
|
||||
|
||||
@staticmethod
|
||||
def _tenant_context_is_global(tenant_context: dict[str, str | None]) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user