fix: disable PocketBase SDK auto-cancellation on group API calls

SSE subscriptions trigger concurrent requests to the same endpoints,
causing auto-cancellation errors. Add $autoCancel: false to group
queries that get called from realtime event handlers.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
congsh
2026-04-18 10:04:26 +08:00
parent 6b684f8600
commit 4dac4bc751
+16 -5
View File
@@ -25,14 +25,16 @@ export async function getUserGroups(): Promise<Group[]> {
if (!user) return []
return pb.collection('groups').getList(1, 50, {
filter: `members ~ "${user.id}"`
filter: `members ~ "${user.id}"`,
$autoCancel: false
}).then(res => res.items as unknown as Group[])
}
// 获取群组详情
export async function getGroup(groupId: string): Promise<Group> {
return pb.collection('groups').getOne(groupId, {
expand: 'members'
expand: 'members',
$autoCancel: false
}) as unknown as Group
}
@@ -82,7 +84,8 @@ export async function getGroupJoinRequests(groupId: string): Promise<JoinRequest
const result = await pb.collection('join_requests').getList(1, 50, {
filter: `group="${groupId}" && status="pending"`,
sort: '-created',
expand: 'user'
expand: 'user',
$autoCancel: false
})
return result.items as unknown as JoinRequest[]
}
@@ -95,7 +98,8 @@ export async function getMyGroupsJoinRequests(): Promise<JoinRequest[]> {
const result = await pb.collection('join_requests').getList(1, 50, {
filter: `group.owner="${user.id}" && status="pending"`,
sort: '-created',
expand: 'user,group'
expand: 'user,group',
$autoCancel: false
})
return result.items as unknown as JoinRequest[]
}
@@ -184,10 +188,17 @@ export function subscribeJoinRequests(groupId: string, callback: (request: JoinR
// 获取群组成员
export async function getGroupMembers(groupId: string) {
const group = await getGroup(groupId)
if (group.expand?.members) {
return group.expand.members
}
const members = group.members as string[]
if (!members || members.length === 0) return []
const users = await pb.collection('users').getList(1, 50, {
filter: members.map(id => `id="${id}"`).join(' || ')
filter: members.map(id => `id="${id}"`).join(' || '),
$autoCancel: false
})
return users.items