feat(asyncify): migrate count blocks (#2374)

This commit is contained in:
cthomas
2025-05-23 09:53:43 -07:00
committed by GitHub
parent b552d7eb35
commit edbddd746d
2 changed files with 6 additions and 8 deletions

View File

@@ -39,14 +39,15 @@ async def list_blocks(
@router.get("/count", response_model=int, operation_id="count_blocks")
def count_blocks(
async def count_blocks(
server: SyncServer = Depends(get_letta_server),
actor_id: Optional[str] = Header(None, alias="user_id"),
):
"""
Count all blocks created by a user.
"""
return server.block_manager.size(actor=server.user_manager.get_user_or_default(user_id=actor_id))
actor = await server.user_manager.get_actor_or_default_async(actor_id=actor_id)
return await server.block_manager.size_async(actor=actor)
@router.post("/", response_model=Block, operation_id="create_block")

View File

@@ -273,15 +273,12 @@ class BlockManager:
@trace_method
@enforce_types
def size(
self,
actor: PydanticUser,
) -> int:
async def size_async(self, actor: PydanticUser) -> int:
"""
Get the total count of blocks for the given user.
"""
with db_registry.session() as session:
return BlockModel.size(db_session=session, actor=actor)
async with db_registry.async_session() as session:
return await BlockModel.size_async(db_session=session, actor=actor)
# Block History Functions