Not exactly. The fields in rows are indices into db.my_table. len(rows) is
a small variable number, say around 8.
But there it is, anyway. Thank you Mr. Niphlod. Good work!
bad_rows = db((db.my_table.id.belongs(rows)) &
(auth.accessible_query('update', db.my_table,
user_id))).select(db.my_table.id)
Speed comparison: 1.4 seconds before change, 0.7 seconds after change. 2X.
Not bad, although I'd prefer 10X :-)
On Thursday, March 21, 2013 9:19:34 PM UTC+8, Niphlod wrote:
>
> So, basically you're doing ....
> "get me 150K rows, put them in a list"
> "for each of them, query the db for permission"
> "if query doesn't return True, scan the 150K list and remove this instance"
>
> Cycling 150K and removing from a list while checking surely will get your
> app killed.
> Firing one query for each row is what seems the problem on the
> "half-dozen" set.
> Try the 'accessible-query' way ....
> rows = db(auth.accessible_query('read', db.my_table,
> auth.user_id)).select(db.my_table.ALL)
> This will do all the required joins "under the hood" and resolve in
> one-query only.
>
> On Thursday, March 21, 2013 12:59:57 PM UTC+1, weheh wrote:
>>
>> I have a table that represents a group, which has permissions on a
>> row-by-row basis. User belongs to certain number of groups, and the rows
>> into the table are kept for convenience sake. I would like to screen that
>> list of rows for a specific permission and exclude those rows from the
>> list. The code looks like this:
>>
>> for row in rows:
>> if not auth.has_permission('update', db.my_table, row):
>> rows.remove(row)
>>
>> Problem is, the auth.has_permission is slow ... on the order of 1.5
>> seconds when scanning a half-dozen row entries. my_table has around 150K
>> rows. How do I speed this up?
>>
>>
>>
>>
--
---
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/groups/opt_out.