aries-askar icon indicating copy to clipboard operation
aries-askar copied to clipboard

Pagination support

Open ff137 opened this issue 3 months ago • 7 comments

Does aries-askar support paginated queries?

Coming from the ACA-Py world, all I can see that's implemented there is fetch by filter, or fetch all.

When working with potentially millions of wallets in a group, pagination is a critical feature to support querying all wallets over HTTP.

If it's already supported in askar, I can work to implement it in the python wrapper + ACA-Py.

ff137 avatar Mar 27 '24 08:03 ff137

I think you can use scan methods, with limit and offset to implement pagination.

This is supported in the Python wrapper I believe, but not yet integrated into ACA-Py AFAIK.

Would be a great addition though!

I think only problem would be that you can't use cursors so it's prone to database changes while fetching next/previous pages

https://github.com/hyperledger/aries-askar/blob/main/src/ffi/store.rs#L542

TimoGlastra avatar Mar 27 '24 09:03 TimoGlastra

Nice! Thanks @TimoGlastra , that helps a lot I'll see what we can get implemented, soon™

ff137 avatar Mar 27 '24 09:03 ff137

@esune @loneil — something to note when thinking about pagination support in ACA-Py.

swcurran avatar Mar 27 '24 15:03 swcurran

The Scan object returned over FFI is essentially a forward-only cursor on the query results. To return pages over multiple HTTP requests, ACA-Py would need to keep the cursor in memory until it is accessed again (for up to 5 minutes, renewing on additional requests maybe). This is possible, but potentially not very reliable if the application is automatically scaling multiple container instances.

andrewwhitehead avatar Mar 27 '24 15:03 andrewwhitehead

fastapi-pagination is a popular library for implementing pagination within fastapi apps. It may offer a helpful reference for a protocol to follow.

The limit-offset pattern will respond with the current page number and the total number of pages. That way the client can increment the offset to get the next page. An ordering mechanism may be important as well

ff137 avatar Mar 27 '24 18:03 ff137

The Scan object returned over FFI is essentially a forward-only cursor on the query results

Would it be possible to create a new scan object with a certain offset instead of keeping the cursor in-memory? Or is there significant performance impact to that?


Also, would there be something that can be used as cursor rather than using offset in askar? I think for large datasets this performs better, and also means it solves records being added deleted, but it does need something sorteable

TimoGlastra avatar Mar 27 '24 18:03 TimoGlastra

Would it be possible to create a new scan object with a certain offset instead of keeping the cursor in-memory? Or is there significant performance impact to that?

Well, yes that's essentially what indy-sdk did, but it may produce duplicate records or miss records due to concurrent updates.

Also, would there be something that can be used as cursor rather than using offset in askar? I think for large datasets this performs better, and also means it solves records being added deleted, but it does need something sorteable

You could maybe put the results into a temporary table. I'm not sure if postgres offers a better option for snapshotting the results that would be accessible from a subsequent DB connection.

andrewwhitehead avatar Mar 27 '24 20:03 andrewwhitehead