rocicorp / replicache

Realtime Sync for Any Backend Stack
https://doc.replicache.dev
1.06k stars 38 forks source link

ReadTransaction.scan ignores limit option when an indexName is provided #1039

Open arv opened 1 year ago

arv commented 1 year ago

https://discord.com/channels/830183651022471199/1050431029602697226/1050431029602697226

In a useSubscribe query, I have the following:

const countWithoutIndex = (
    await txn
        .scan({
            limit: 1,
        })
        .entries()
        .toArray()
).length;

const countWithIndex = (
    await txn
        .scan({
            indexName: "foo",
            limit: 1,
            start: {
                key: ["bar"],
            },
        })
        .entries()
        .toArray()
).length;

I observed that countWithoutIndex is always 1 (respecting the limit option as expected), but countWithIndex is not 1. It seems that the scan iterator does start at the provided index value ("bar"), but it doesn't stop at the given limit.