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

Pablo Platt <>
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.

Thanks




________________________________
From: Ulf Wiger <>
To: Pablo Platt <>
Cc: 
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)].
[true,true,true,true,true,true,true,true,true,true,true,
true,true,true,true,true,true,true,true,true,true,true,true,
true,true,true,true,true,true|...]

3> QH = qlc:q([X || X <- gproc:table(all)]).    
{qlc_handle,{qlc_lc,#Fun<erl_eval.20.67289768>,
                    {qlc_opt,false,false,-1,any,[],any,524288,allowed}}}

4> Cu = qlc:cursor(QH).                        
{qlc_cursor,{<0.74.0>,<0.67.0>}}

5> qlc:next_answers(Cu, 3).
[{{n,l,1},<0.67.0>,undefined},
{{n,l,2},<0.67.0>,undefined},
{{n,l,3},<0.67.0>,undefined}]

6> qlc:next_answers(Cu, 3).
[{{n,l,4},<0.67.0>,undefined},
{{n,l,5},<0.67.0>,undefined},
{{n,l,6},<0.67.0>,undefined}]

7> qlc:next_answers(Cu, 3).
[{{n,l,7},<0.67.0>,undefined},
{{n,l,8},<0.67.0>,undefined},
{{n,l,9},<0.67.0>,undefined}]


BR,
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.
http://erlang-solutions.com


      


More information about the erlang-questions mailing list