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

Pablo Platt pablo.platt@REDACTED
Mon Nov 22 22:11:37 CET 2010

I'll put the cursor in a process as you suggest and kill it after 10 minutes.
If a user request a page and the cursor process is already dead
I'll either automatically paginate until I reach the page
or just send an error.


From: Ulf Wiger <ulf.wiger@REDACTED>
To: Pablo Platt <pablo.platt@REDACTED>
Cc: erlang-questions@REDACTED
Sent: Mon, November 22, 2010 8:42:46 AM
Subject: Re: [erlang-questions] pagination (skip, limit) ets items (gproc pids)

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 
> suggested above?
> Thanks

Ulf Wiger, CTO, Erlang Solutions, Ltd.


More information about the erlang-questions mailing list