refactor: reuse routing and remove unused analysis helpers
Generic Container CI/CD / test-build-publish (push) Successful in 4m3s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 4m3s

This commit is contained in:
2026-11-09 18:49:32 +08:00
parent 6a4478bfe4
commit e47c61c121
6 changed files with 107 additions and 103 deletions
+12 -2
View File
@@ -3,6 +3,8 @@
from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import Any, AsyncIterator
from uuid import UUID
from sqlalchemy.ext.asyncio import AsyncSession
from psycopg import AsyncConnection
from app.auth.project_dependencies import ProjectContext
from app.infra.db.project_routing import ActiveProjectRouting
@@ -18,16 +20,24 @@ from app.auth.project_dependencies import (
get_project_timescale_connection,
)
from app.infra.db.metadb.database import get_metadata_session
from app.infra.db.metadb.repositories.metadata_repository import MetadataRepository
from app.infra.db.metadb.repositories.metadata_repository import MetadataRepository, ProjectDbRouting
from app.infra.db.project_routing import activate_project_routing
class QueryMetadataRepository(MetadataRepository):
async def get_project_db_routing(self, project_id, role):
def __init__(self, session: AsyncSession):
super().__init__(session)
self._routing: dict[tuple[UUID, str], ProjectDbRouting | None] = {}
async def get_project_db_routing(self, project_id: UUID, role: str) -> ProjectDbRouting | None:
key = (project_id, role)
if key in self._routing:
return self._routing[key]
routing = await super().get_project_db_routing(project_id, role)
# Existing connection generators obtain routing before awaiting a pool.
# End that implicit SELECT transaction here, before the network wait.
await self.session.commit()
self._routing[key] = routing
return routing