Skip to content

Commit 4ebe87d

Browse files
committed
fix: indexeddb query continue issue
1 parent aabc7d7 commit 4ebe87d

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

crates/restsend-wasm/test/conversations.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ describe('Conversations', async function () {
123123
expect(syncDone).toBe(true)
124124
expect(newItems[0].content.type).toEqual('recall')
125125
expect(newItems[0].content.text).toEqual(recallId)
126-
expect(newItems[1].recall).toBe(false)
127-
expect(newItems[1].content.type).toEqual('text')
126+
expect(newItems[1].recall).toBe(true)
127+
expect(newItems[1].content.type).toEqual('recalled')
128128
})
129129

130130
it('#sync sync last logs without cache', async () => {

crates/restsend/src/storage/indexeddb.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ impl<T: StoreModel + 'static> IndexeddbTable<T> {
322322
.ok()?;
323323

324324
let limit = option.limit;
325+
let option_start_sort_value = option.start_sort_value;
325326
let items_clone = items.clone();
326327
let cursor_req_ref = cursor_req.clone();
327328
let on_success_callback = Rc::new(RefCell::new(None));
@@ -349,14 +350,22 @@ impl<T: StoreModel + 'static> IndexeddbTable<T> {
349350
let r = match cursor.value() {
350351
Ok(v) => match serde_wasm_bindgen::from_value::<StoreValue>(v) {
351352
Ok(v) => {
352-
let mut items_count = 0;
353353
if let Ok(item) = T::from_str(&v.value) {
354+
if v.sortkey as f64 == start_sort_value {
355+
cursor.continue_().ok();
356+
return;
357+
}
358+
354359
if let Some(items) = items_ref.borrow_mut().as_mut() {
355360
items.push(item);
356-
items_count = items.len();
361+
let items_count = items.len();
362+
363+
if items_count < (limit + 1) as usize {
364+
cursor.continue_().ok();
365+
return;
366+
}
357367
}
358-
}
359-
if items_count < (limit + 1) as usize {
368+
} else {
360369
cursor.continue_().ok();
361370
return;
362371
}

js/restsend_wasm.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,27 +2556,27 @@ function __wbg_get_imports() {
25562556
const ret = false;
25572557
return ret;
25582558
};
2559-
imports.wbg.__wbindgen_closure_wrapper1371 = function(arg0, arg1, arg2) {
2559+
imports.wbg.__wbindgen_closure_wrapper1372 = function(arg0, arg1, arg2) {
25602560
const ret = makeMutClosure(arg0, arg1, 654, __wbg_adapter_54);
25612561
return ret;
25622562
};
2563-
imports.wbg.__wbindgen_closure_wrapper1372 = function(arg0, arg1, arg2) {
2563+
imports.wbg.__wbindgen_closure_wrapper1373 = function(arg0, arg1, arg2) {
25642564
const ret = makeMutClosure(arg0, arg1, 654, __wbg_adapter_54);
25652565
return ret;
25662566
};
2567-
imports.wbg.__wbindgen_closure_wrapper1373 = function(arg0, arg1, arg2) {
2567+
imports.wbg.__wbindgen_closure_wrapper1374 = function(arg0, arg1, arg2) {
25682568
const ret = makeMutClosure(arg0, arg1, 654, __wbg_adapter_59);
25692569
return ret;
25702570
};
2571-
imports.wbg.__wbindgen_closure_wrapper1376 = function(arg0, arg1, arg2) {
2571+
imports.wbg.__wbindgen_closure_wrapper1377 = function(arg0, arg1, arg2) {
25722572
const ret = makeMutClosure(arg0, arg1, 654, __wbg_adapter_54);
25732573
return ret;
25742574
};
2575-
imports.wbg.__wbindgen_closure_wrapper1378 = function(arg0, arg1, arg2) {
2575+
imports.wbg.__wbindgen_closure_wrapper1379 = function(arg0, arg1, arg2) {
25762576
const ret = makeMutClosure(arg0, arg1, 654, __wbg_adapter_54);
25772577
return ret;
25782578
};
2579-
imports.wbg.__wbindgen_closure_wrapper2284 = function(arg0, arg1, arg2) {
2579+
imports.wbg.__wbindgen_closure_wrapper2285 = function(arg0, arg1, arg2) {
25802580
const ret = makeMutClosure(arg0, arg1, 848, __wbg_adapter_66);
25812581
return ret;
25822582
};

js/restsend_wasm_bg.wasm

711 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)