fix(phase3): add $autoCancel:false to prevent SDK auto-cancellation

PocketBase JS SDK auto-cancels pending requests when a new request
targets the same collection. This causes errors when loadLedgers and
getLedgerSummary run in parallel via Promise.all. Added $autoCancel:false
to all API calls in ledgers.ts and assets.ts, matching project convention.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
congsh
2026-04-18 20:05:27 +08:00
parent e4b730c8db
commit dc11ef90fd
2 changed files with 24 additions and 23 deletions
+17 -17
View File
@@ -32,7 +32,7 @@ export async function createLedger(data: CreateLedgerData): Promise<Ledger> {
...data,
creator: user?.id || '',
relatedMembers: data.relatedMembers || []
})
}, { $autoCancel: false })
return record as unknown as Ledger
}
@@ -45,11 +45,9 @@ export async function listLedgers(
if (type) filter += ` && type="${type}"`
if (category) filter += ` && category="${category}"`
if (month) {
// month format: "2026-04"
const start = `${month}-01 00:00:00`
const year = parseInt(month.slice(0, 4))
const mon = parseInt(month.slice(5, 7))
// 下个月的第一天
const nextMonth = mon === 12 ? `${year + 1}-01` : `${year}-${String(mon + 1).padStart(2, '0')}`
const end = `${nextMonth}-01 00:00:00`
filter += ` && occurredAt>="${start}" && occurredAt<"${end}"`
@@ -58,7 +56,8 @@ export async function listLedgers(
const result = await pb.collection('ledgers').getList(page, limit, {
filter,
sort: '-occurredAt',
expand: 'creator,relatedMembers'
expand: 'creator,relatedMembers',
$autoCancel: false
})
return { items: result.items as unknown as Ledger[], total: result.totalItems }
}
@@ -67,12 +66,12 @@ export async function updateLedger(
ledgerId: string,
data: Partial<CreateLedgerData>
): Promise<Ledger> {
const record = await pb.collection('ledgers').update(ledgerId, data)
const record = await pb.collection('ledgers').update(ledgerId, data, { $autoCancel: false })
return record as unknown as Ledger
}
export async function deleteLedger(ledgerId: string): Promise<void> {
await pb.collection('ledgers').delete(ledgerId)
await pb.collection('ledgers').delete(ledgerId, { $autoCancel: false })
}
export async function getLedgerSummary(
@@ -85,20 +84,21 @@ export async function getLedgerSummary(
const batchSize = 500
let hasMore = true
while (hasMore) {
let filter = `group="${groupId}"`
if (month) {
const start = `${month}-01 00:00:00`
const year = parseInt(month.slice(0, 4))
const mon = parseInt(month.slice(5, 7))
const nextMonth = mon === 12 ? `${year + 1}-01` : `${year}-${String(mon + 1).padStart(2, '0')}`
const end = `${nextMonth}-01 00:00:00`
filter += ` && occurredAt>="${start}" && occurredAt<"${end}"`
}
let filter = `group="${groupId}"`
if (month) {
const start = `${month}-01 00:00:00`
const year = parseInt(month.slice(0, 4))
const mon = parseInt(month.slice(5, 7))
const nextMonth = mon === 12 ? `${year + 1}-01` : `${year}-${String(mon + 1).padStart(2, '0')}`
const end = `${nextMonth}-01 00:00:00`
filter += ` && occurredAt>="${start}" && occurredAt<"${end}"`
}
while (hasMore) {
const result = await pb.collection('ledgers').getList(page, batchSize, {
filter,
fields: 'type,amount'
fields: 'type,amount',
$autoCancel: false
})
for (const item of result.items as any[]) {