Pagination with mnesia could be quite tricky.
mnesia adapter contains the following function:
count(Conn, Type, Conditions) ->
    length(find(Conn, Type, Conditions, all, 0, id, ascending)).

So every time you do Count on mnesia boss_db will load full query result in 
memory, with all data of all fields.

And as you do boss_db:find(Model, Conditions, ArgList) again, you will do 
the same query and load the same data again. 

You may not notice this on developers box when there's only so much of 
data, but on real server you will have huge hit on performance and memory. 

Of course there's no such problem on postgres or mysql, but count(*)..where 
...  is quite heavy operation even in RDBMS world

среда, 22 января 2014 г., 19:17:20 UTC+4 пользователь David Welton написал:
>
> Would it be worth including something like this directly in boss_db ? 
>
> paginate(Model, Conditions, Args) -> 
>     Page = proplists:get_value(page, Args, 1), 
>     PageSize = proplists:get_value(page_size, Args, ?DEFAULT_PAGE_SIZE), 
>     ArgList = proplists:delete(page_size, proplists:delete(page, Args)) ++ 
>         [{offset, PageSize * (Page - 1)}, {limit, PageSize}], 
>     Total = boss_db:count(Model, Conditions), 
>     TotalPages = (Total div PageSize) + (case Total rem PageSize of 
>                                              0 -> 0; 
>                                              _ -> 1 
>                                          end), 
>     {Page, TotalPages, boss_db:find(Model, Conditions, ArgList)}. 
>
> -- 
> David N. Welton 
>
> http://www.welton.it/davidw/ 
>
> http://www.dedasys.com/ 
>

-- 
You received this message because you are subscribed to the Google Groups 
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/chicagoboss/abd60772-8956-49b6-ba66-273e057fb286%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to