every time you invoke has_membership you ask web2py to verify if in that 
instance the user belongs to a particular group. It translates to 1 or more 
queries to the backend.
"my" method instead looks into the groups stored in the session (fetched 
only once at login), so it doesn't need the roundtrip to check the 
membership.

The only con is that if a user is logged in it retains the membership it 
had at the time of the login, so removal of membership is not "translated" 
to the impossibility to access the decorated function until the user logs 
out and logins again. 

I prefer using relatively short session timeouts and save zillions of db 
queries rather than using has_membership, even if has_membership is 
"strictly" correct (instant verification) while mine isn't.

On Friday, November 11, 2016 at 4:11:46 PM UTC+1, Richard wrote:
>
> Simone,
>
> I don't understand why you say you cached groups, from what you showed you 
> only prevent accessing db until the very end with the lambda no?
>
> Richard
>
> On Fri, Nov 11, 2016 at 8:16 AM, Niphlod <[email protected] <javascript:>> 
> wrote:
>
>> any and all are definitely python syntax.
>>
>> I do this using the cached groups, so I don't reach the db for every check
>>
>>
>> ALLOWED = set(('admin', 'contributor'))
>> @auth.requires(lambda: auth.user_id and ALLOWED & set(auth.user_groups.
>> values()))
>>
>>
>>
>> On Friday, November 11, 2016 at 1:55:25 PM UTC+1, 黄祥 wrote:
>>>
>>> i'm interested in *ANY* and *ALL* in your code, but can't find anything 
>>> that contain *ANY* or *ALL* on the link you provide, is it DAL, web2py 
>>> or python syntax?
>>>
>>> best regards,
>>> stifan
>>>
>> -- 
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to