Skip to content

Commit 60d72a3

Browse files
committed
fix(sync): OfflineQueue 版本排序改内存排序(Dexie Table 无 sortBy)
1 parent e2e4b85 commit 60d72a3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎client/src/lib/sync/OfflineQueue.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ export class OfflineQueue {
4545
// SYNC2-L4: 取最大值按 version(单调自增)而非 createdAt——Date 毫秒
4646
// 精度下同一毫秒的并发写入会取到错误基线,产生重复版本号
4747
// GW-3: version 非索引字段,orderBy 会抛 SchemaError(Dexie 硬性要求)——
48-
// 改用 sortBy 内存排序(队列数据量小,性能可接受)
48+
// 改用 toArray 后内存排序(队列数据量小,性能可接受)
4949
await db.transaction('rw', db.offlineQueue, async () => {
50-
const items = await db.offlineQueue.sortBy('version');
50+
const items = await db.offlineQueue.toArray();
51+
items.sort((a, b) => (a.version ?? 0) - (b.version ?? 0));
5152
const version = items.length > 0 ? (items[items.length - 1].version || 0) + 1 : 1;
5253

5354
await db.offlineQueue.add({
@@ -71,8 +72,9 @@ export class OfflineQueue {
7172
*/
7273
async getPendingItems(): Promise<OfflineQueueItem[]> {
7374
// GW-3: version 非索引字段,orderBy 抛 SchemaError(Dexie 硬性要求)——
74-
// 原实现从未真正工作;改 sortBy 内存排序
75-
return db.offlineQueue.sortBy('version');
75+
// 原实现从未真正工作;改 toArray 后内存排序
76+
const items = await db.offlineQueue.toArray();
77+
return items.sort((a, b) => (a.version ?? 0) - (b.version ?? 0));
7678
}
7779

7880
/**
@@ -127,7 +129,8 @@ export class OfflineQueue {
127129
async getReadyItems(maxRetries: number = 5): Promise<OfflineQueueItem[]> {
128130
const now = Date.now();
129131
// GW-3: 同 getPendingItems——orderBy('version') 抛 SchemaError,改内存排序
130-
const items = await db.offlineQueue.sortBy('version');
132+
const items = await db.offlineQueue.toArray();
133+
items.sort((a, b) => (a.version ?? 0) - (b.version ?? 0));
131134
return items.filter(
132135
item =>
133136
item.retryCount < maxRetries &&

0 commit comments

Comments
 (0)