About lazy rows in dal

99 views
Skip to first unread message

Carlos Cesar Caballero Díaz

unread,
Jul 4, 2016, 2:14:14 PM7/4/16
to web...@googlegroups.com
Hi, some ORMs have a lazy option for reduce queries when we ask for
references, for example, something like:


rows = db(db.mytable.id > 0).select()

relation_name1 = rows[0].id_relation.name

relation_name2 = rows[1].id_relation.name


Will generate 3 querys, but with the lazy option, something like:


rows = db(db.mytable.id > 0).select(lazy=true)

relation_name1 = rows[0].id_relation.name

relation_name2 = rows[1].id_relation.name


Will generate only one query, and in that way the DAL will make the
joins in the query and populate the reference rows.

Is posible do something like this with pyDAL?

Greetings.

--
Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

Anthony

unread,
Jul 4, 2016, 11:19:50 PM7/4/16
to web2py-users
I'd say the first option is "lazy", as it defers the query until the data are requested, but terminology aside, the DAL does not have built-in functionality to handle the second option. Note, on the developers list, Massimo has just proposed a .join method on Rows that would do something similar, but with two queries instead of 3+. Alternatively, note that .select() takes a "processor" argument, so I suppose you could implement a custom processor that takes a query involving a join and instead of returning the typical join result set returns a set of rows with nested records.

Anthony

Carlos Cesar Caballero Díaz

unread,
Jul 5, 2016, 10:40:50 AM7/5/16
to web...@googlegroups.com
Thanks Anthony, I was looking at the DAL code and it is kind intimidating (at least for me)... Is out there some example of using the "processor" argument?

Greetings.

El 04/07/16 a las 23:19, Anthony escribió:
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Massimo Di Pierro

unread,
Jul 5, 2016, 11:00:24 AM7/5/16
to web2py-users

Anthony

unread,
Jul 5, 2016, 11:06:46 AM7/5/16
to web2py-users
On Tuesday, July 5, 2016 at 10:40:50 AM UTC-4, Carlos Cesar Caballero wrote:
Thanks Anthony, I was looking at the DAL code and it is kind intimidating (at least for me)... Is out there some example of using the "processor" argument?

Here's one example: https://groups.google.com/d/msg/web2py/jtb1BsHwQNM/cPTd-J62NcgJ

Your processor function should take four arguments, as noted in the example. The first argument will be the raw records from the database driver, which will be a list of tuples. The third argument will be the column names returned by the database driver.

Anthony

Carlos Cesar Caballero Díaz

unread,
Jul 5, 2016, 2:13:46 PM7/5/16
to web...@googlegroups.com
Thanks Anthony, I will work on that.

Greetings.


El 05/07/16 a las 11:06, Anthony escribió:

Massimo Di Pierro

unread,
Jul 5, 2016, 2:28:04 PM7/5/16
to web2py-users


On Monday, 4 July 2016 13:14:14 UTC-5, Carlos Cesar Caballero wrote:

Richard Vézina

unread,
Mar 3, 2017, 1:49:09 PM3/3/17
to web2py-users
Hello Anthony,

I face some scaling issue with lazy_option plugin, but I am not sure I understand how the .join method you mention can help solve the issue...

I also customize lazy_option...

I think the main problem with lazy_option is that it load all the data present in the reference table, so once your database start to be large it start to take a lot of time initializing all these rows...

I think the way to workaround that would be to add a "load more" feature to lazy_option...

Also, I am not sure that lazy_option is not load only once the form/DOM is loaded once, mean it get lazy just once the DOM have been initialize once, so not that lazy...

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

Richard Vézina

unread,
Mar 3, 2017, 3:57:29 PM3/3/17
to web2py-users
:(

One part of my problem is something I introduce to compute the width of the input field to set dynamically the field width... Is too slow even in case I use itemgetter as explained here :


So I guess I can't improve the display of the form select that way...

But even then I think at some point the number of record affect form time load which compromise the use of lazy_option widget as the data set get bigger and bigger...

Richard
Reply all
Reply to author
Forward
0 new messages