Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openrag/services/orchestrators/partition_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@ def _meta(row: dict[str, Any]) -> dict[str, Any]:

async def list_members(self, partition: str) -> list[dict]:
await self._ensure_partition(partition)
return await self._membership_repo.list_partition_members(partition)
members = await self._membership_repo.list_partition_members(partition)
users = await asyncio.gather(*(self._user_repo.get_user(m["user_id"]) for m in members))
for member, user in zip(members, users, strict=True):
member["display_name"] = user.display_name if user else None
Comment on lines +677 to +680

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

ast-grep outline openrag/services/orchestrators/partition_service.py --view expanded

Repository: linagora/openrag

Length of output: 3527


🏁 Script executed:

sed -n '665,685p' openrag/services/orchestrators/partition_service.py
printf '\n---\n'
rg -n "def get_user|class .*User|get_user\\(" openrag -g '*.py'

Repository: linagora/openrag

Length of output: 4635


🏁 Script executed:

sed -n '90,125p' openrag/services/persistence/user_repo.py
printf '\n---\n'
sed -n '1,120p' openrag/core/ports/user_repo.py
printf '\n---\n'
rg -n "get_users|list_users_by|batch.*user|user_ids" openrag/services openrag/core -g '*.py'

Repository: linagora/openrag

Length of output: 3415


Bound the membership user lookups. asyncio.gather(...) launches one DB call per member, and UserRepository has no batch fetch here. Large partitions can overwhelm the pool; chunk these lookups or add a bulk user query.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openrag/services/orchestrators/partition_service.py` around lines 677 - 680,
Bound the concurrent user lookups in the partition membership enrichment flow
around _membership_repo.list_partition_members and _user_repo.get_user. Fetch
member users in bounded chunks, preserving the existing member order and
display_name assignment while avoiding one unbounded asyncio.gather call for
large partitions.

return members

async def add_member(self, partition: str, user_id: int, role: str) -> None:
await self._ensure_partition(partition)
Expand Down
26 changes: 25 additions & 1 deletion tests/unit/services/orchestrators/test_partition_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,18 @@ async def query_chunks_by_filter(self, collection, filters, output_fields=None):


class FakeUserRepo:
def __init__(self, existing: set[int] | None = None):
def __init__(self, existing: set[int] | None = None, display_names: dict[int, str] | None = None):
self._existing = existing if existing is not None else set()
self._display_names = display_names or {}

async def user_exists(self, user_id: int) -> bool:
return user_id in self._existing

async def get_user(self, user_id: int):
if user_id not in self._existing:
return None
return SimpleNamespace(display_name=self._display_names.get(user_id))


def _svc(
*,
Expand Down Expand Up @@ -830,6 +836,24 @@ async def test_list_members_missing_partition_404():
await _svc(prepo=FakePartitionRepo(set())).list_members("x")


@pytest.mark.asyncio
async def test_list_members_enriches_with_display_name():
mrepo = FakeMembershipRepo(members={(9, "p")})
urepo = FakeUserRepo({9}, display_names={9: "Alice"})
svc = _svc(prepo=FakePartitionRepo({"p"}), mrepo=mrepo, urepo=urepo)
members = await svc.list_members("p")
assert members == [{"user_id": 9, "role": "viewer", "display_name": "Alice"}]


@pytest.mark.asyncio
async def test_list_members_missing_user_display_name_is_none():
mrepo = FakeMembershipRepo(members={(9, "p")})
urepo = FakeUserRepo(set()) # user_id 9 no longer exists
svc = _svc(prepo=FakePartitionRepo({"p"}), mrepo=mrepo, urepo=urepo)
members = await svc.list_members("p")
assert members[0]["display_name"] is None


@pytest.mark.asyncio
async def test_add_member_checks_partition_and_user():
mrepo = FakeMembershipRepo()
Expand Down
3 changes: 2 additions & 1 deletion ui/src/lib/api/partitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { request } from "./client";
// POST /partition/{p} create (name in path, NO body; caller becomes owner) → 201
// PATCH /partition/{p} update config → PartitionDetailResponse
// DELETE /partition/{p} delete → 204
// GET /partition/{p}/users members → { members: [{ user_id, role, added_at }] }
// GET /partition/{p}/users members → { members: [{ user_id, display_name, role, added_at }] }
// POST /partition/{p}/users add member (multipart: user_id, role)
// PATCH /partition/{p}/users/{user_id} change role (multipart: role)
// DELETE /partition/{p}/users/{user_id} remove member
Expand Down Expand Up @@ -194,6 +194,7 @@ export function listPartitionFiles(name: string, limit?: number): Promise<{ file

export interface PartitionMember {
user_id: number;
display_name: string | null;
role: PartitionRole;
added_at: string | null;
}
Expand Down
10 changes: 6 additions & 4 deletions ui/src/pages/admin/partitions/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ function UsersTab({ partitionName }: { partitionName: string }) {
<Table>
<TableHeader>
<TableRow>
<TableHead>User ID</TableHead>
<TableHead>User</TableHead>
<TableHead>Role</TableHead>
<TableHead>Added</TableHead>
{canManage && <TableHead>Actions</TableHead>}
Expand All @@ -476,8 +476,10 @@ function UsersTab({ partitionName }: { partitionName: string }) {
<TableBody>
{usersQuery.data.members.map((user) => (
<TableRow key={user.user_id}>
<TableCell className="font-mono text-sm">
{user.user_id}
<TableCell className="text-sm">
{user.display_name || (
<span className="font-mono text-muted-foreground">{user.user_id}</span>
)}
</TableCell>
Comment on lines +479 to 483

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep a stable identifier visible with display names.

Lines 480-482 and 513 show only the display name when available. Display names are not guaranteed to be unique, so administrators may be unable to distinguish members or confirm which account will be removed. Keep user_id as secondary text, a tooltip, or include it in the confirmation.

Also applies to: 511-514

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/src/pages/admin/partitions/detail.tsx` around lines 479 - 483, The member
rows currently hide user_id when display_name exists, making accounts ambiguous.
Update the rendering near the user display-name cells, including both affected
occurrences, to always keep user_id visible as secondary text, a tooltip, or in
the removal confirmation while preserving the existing display-name
presentation.

<TableCell>
{canManage ? (
Expand Down Expand Up @@ -508,7 +510,7 @@ function UsersTab({ partitionName }: { partitionName: string }) {
<TableCell>
<ConfirmDialog
title="Remove User"
description={`Remove user "${user.user_id}" from this partition? They will lose access to partition data.`}
description={`Remove user "${user.display_name || user.user_id}" from this partition? They will lose access to partition data.`}
onConfirm={() => removeMutation.mutate(user.user_id)}
>
<Button
Expand Down
Loading