You can improve your example with
query = (db.advertisement.owner==auth.user.id)
links = db(query).select(orderby=db.advertisement.posted_on)
for b in links:
query=(db.published.advertisement_id==b.id)
res = db(query).select()
for a in res:
print a.mag_id
but this would not make it any faster.
I order to make it faster you would have to change your model. How
depends on usage statistics and types of queries. Everything you do is
a result of a tradeoff.
You should look into
from gluon.conrtib.gql import gae
Field('publications',gae.ListProperty(int))
which maps into a the equivalent GAE ListProperty.
You may also want to consider denormalizing the database.
In both cases you gain speed but may lose referential integrity.
There are many ways to do this and which one
On Jan 14, 1:11 am, Miguel <[email protected]> wrote:
> Hi
>
> Advertisements can be published in different magazines. I represent
> this with the following tables:
>
> db.define_table("magazine",
> SQLField("owner",db.auth_user, writable=False, readable=False))
>
> db.define_table("advertisement",
> SQLField("owner",db.auth_user,writable=False, readable=False),
> SQLField("description", "text", notnull=True, label = T
> ("Description"),
> SQLField("mag_id", db.magazine,writable=False, readable=False))
>
> db.define_table("published",
> SQLField("advertisement_id", db.advertisement),
> SQLField("mag_id", db.magazine),
> SQLField("url", "string",length=2048, notnull=True,
> default=None))
>
> What I need is a query that, given a user, for each of his
> advertisement gives me the magazines it is printed on.
> Since on GAE I cannot have joins I simulated this by doing the
> following:
>
> query = (db.advertisement.id>0)&(db.advertisement.owner ==
> auth.user.id)
> links = db(query).select(orderby=db.advertisement.posted_on)
>
> # links now contains all the advertisements for the logged-in user
>
> for b in links:
> query=(db.published.id>0) & (db.published.advertisement_id ==
> b.id)
> res = db(query).select()
> for a in res:
> print a.mag_id # prints the id of the magazine the
> advertisement is published in
>
> Is there a better way of doing this in GAE? Performance is one of my
> main concerns here.
>
> thanks
> -M
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.