[erlang-questions] pagination (skip, limit) ets items (gproc pids)

Ulf Wiger ulf.wiger@REDACTED
Mon Nov 22 07:42:46 CET 2010

Hi Pablo,

Paging can be done using QLC cursors, and if you want, you
can create a special pager process that repeatedly calls 
qlc:next_answers/2. Using gproc, you could register the pager 
process using a request cookie or other identifier that makes it
convenient for you to find it.

The following shell dialogue might illustrate:

2> [gproc:reg({n,l,K}) || K <- lists:seq(1,30)].

3> QH = qlc:q([X || X <- gproc:table(all)]).    

4> Cu = qlc:cursor(QH).                         

5> qlc:next_answers(Cu, 3).

6> qlc:next_answers(Cu, 3).

7> qlc:next_answers(Cu, 3).

Ulf W

On 20 Nov 2010, at 01:18, Pablo Platt wrote:

> Hi
> I'm using gproc to save user sessions.
> I want to present a list of online users in an admin html page.
> I have a large number of sessions.
> Is it possible to paginate the list similar to how SQL use skip and limit?
> The admin will see a list of 1-10 online users and have links previous and next 
> to see previous and next group of users.
> I can't use ets continuation because I'll have to save it and reuse it which is 
> hard in a website.
> The only way I see to solve it is to use ets:match(Tab, Pattern, Limit) several 
> times.
> For example, if the admin requests for users 50-60 I'll do ets:match 5 times 
> when using the returned continuation.
> Is there a better way?
> Is there a reason why Skip isn't implemented even if it'll be implemented like a 
> suggested above?
> Thanks

Ulf Wiger, CTO, Erlang Solutions, Ltd.

More information about the erlang-questions mailing list