Janzert schrieb:
 > I've attached my test project and scripts to the trac issue* if
 > someone wants to double check my methods.

I'm using the following add-on, maybe it's useful for you, too ;-)
https://addons.mozilla.org/en-US/thunderbird/addon/5759

> As you can see the current method of iterating through the groups is 
> actually 130 to 150 times faster than single query methods.

I think this is because the current method uses the group.permissions 
lists in the database session if possible. I.e. if you run it in a loop, 
it will become very efficient. However, in reality this function will be 
called only once or a few times per request, always in a fresh session. 
You can simulate this with turbogears.database.session.expire_all(). 
Doing so, I measured that the join method is about 3 times faster and 
the exists method is about 2 times faster than the old method (similar 
for both SQLite and Postgres 8.3).

So it depends on how people use the permissions attribute. If used more 
than 2 times per request, the old method is faster. One solution for 
getting good performance in both cases is using the join method and 
caching the permissions in the User instance:

     def permissions(self):
         try:
             p = User._permissions
         except AttributeError:
             p = set(Permission.query.distinct().join(['groups',
                 'users']).filter_by(user_id=self.user_id))
             User._permissions = p
         return p

Another interesting question is why the join method is in fact faster 
than the exists method, though you would expect the opposite. See also:

http://wrschneider.blogspot.com/2004/12/postgresql-performance-of-where-exists.html

In this case we have a chained exists, maybe this makes it difficult to 
optimize for the database.

-- Christoph

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to