feat: temp remove disabling enable_seqscan setting (#3443)

This commit is contained in:
cthomas
2025-07-20 23:02:23 -07:00
committed by GitHub
parent 8ed1505cea
commit d85d275f6f
2 changed files with 8 additions and 21 deletions

View File

@@ -5,7 +5,7 @@ from functools import wraps
from pprint import pformat
from typing import TYPE_CHECKING, List, Literal, Optional, Tuple, Union
from sqlalchemy import Sequence, String, and_, delete, func, or_, select, text
from sqlalchemy import Sequence, String, and_, delete, func, or_, select
from sqlalchemy.exc import DBAPIError, IntegrityError, TimeoutError
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Mapped, Session, mapped_column
@@ -512,14 +512,9 @@ class SqlalchemyBase(CommonSqlalchemyMetaMixins, Base):
query, query_conditions = cls._read_multiple_preprocess(identifiers, actor, access, access_type, check_is_deleted, **kwargs)
if query is None:
raise NoResultFound(f"{cls.__name__} not found with identifier {identifier}")
if is_postgresql_session(db_session):
await db_session.execute(text("SET LOCAL enable_seqscan = OFF"))
try:
result = await db_session.execute(query)
item = result.scalar_one_or_none()
finally:
if is_postgresql_session(db_session):
await db_session.execute(text("SET LOCAL enable_seqscan = ON"))
result = await db_session.execute(query)
item = result.scalar_one_or_none()
if item is None:
raise NoResultFound(f"{cls.__name__} not found with {', '.join(query_conditions if query_conditions else ['no conditions'])}")

View File

@@ -1,6 +1,6 @@
from typing import List, Optional
from sqlalchemy import select, text
from sqlalchemy import select
from letta.constants import DEFAULT_ORG_ID
from letta.data_sources.redis_client import get_redis_client
@@ -8,7 +8,6 @@ from letta.helpers.decorators import async_redis_cache
from letta.log import get_logger
from letta.orm.errors import NoResultFound
from letta.orm.organization import Organization as OrganizationModel
from letta.orm.sqlalchemy_base import is_postgresql_session
from letta.orm.user import User as UserModel
from letta.otel.tracing import trace_method
from letta.schemas.user import User as PydanticUser
@@ -157,16 +156,9 @@ class UserManager:
async def get_actor_by_id_async(self, actor_id: str) -> PydanticUser:
"""Fetch a user by ID asynchronously."""
async with db_registry.async_session() as session:
# Turn off seqscan to force use pk index
if is_postgresql_session(session):
await session.execute(text("SET LOCAL enable_seqscan = OFF"))
try:
stmt = select(UserModel).where(UserModel.id == actor_id)
result = await session.execute(stmt)
user = result.scalar_one_or_none()
finally:
if is_postgresql_session(session):
await session.execute(text("SET LOCAL enable_seqscan = ON"))
stmt = select(UserModel).where(UserModel.id == actor_id)
result = await session.execute(stmt)
user = result.scalar_one_or_none()
if not user:
raise NoResultFound(f"User not found with id={actor_id}")