@service.json
def block_user():
data = json.loads(request.body.read())
user = db(db.users.id==data['id']).select().first()
user.update_record(banned=True, banned_by=auth.user_id)
alerts = db(db.alerts.alerts_id==data['id']).update(archived=True)
db.commit()
return "ok"
My guess would be that you're using sqlite and the database is locking you. Which is easy to happen if you have a few people requesting updates every 5 seconds and you're trying to write on it, as the write will only go forward once sqlite gets its process an EXCLUSIVE lock which requires all readers which have SHARED locks to stop reading first.One thing you can do is to cache the result returned in the first case so it doesn't hit the database. Then you can clear the cache when you make changes that would change the result. If this doesn't work then it's time to change databases.
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6z13PTcZ5io/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Then I'm sorry but I have no idea why it's taking so long. You need to profile it.It may just be a question of tuning MySQL, optimizing the tables, etc. Have you tried mysqltuner?
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6z13PTcZ5io/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If this is in a controller, do you need the line: db.commit() ??
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6z13PTcZ5io/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>>> db._timings
[('SET FOREIGN_KEY_CHECKS=1;', 0.0002541542053222656), ("SET sql_mode='NO_BACKSLASH_ESCAPES';", 0.0002338886260986328)]
>>> db((db.alerts.alerts_id==1)&(db.alerts.archived != True)).update(archived=True, crime="Robo", operator_id=1)
23
>>> db._timings
[('SET FOREIGN_KEY_CHECKS=1;', 0.0002541542053222656), ("SET sql_mode='NO_BACKSLASH_ESCAPES';", 0.0002338886260986328), ("UPDATE alerts SET archived='T',operator_id=1,crime='Robo' WHERE ((alerts.alerts_id = 1) AND (alerts.archived <> 'T'));", 0.010937213897705078)]
>>> db.commit()
>>> db._timings
[('SET FOREIGN_KEY_CHECKS=1;', 0.0002541542053222656), ("SET sql_mode='NO_BACKSLASH_ESCAPES';", 0.0002338886260986328), ("UPDATE alerts SET archived='T',operator_id=1,crime='Robo' WHERE ((alerts.alerts_id = 1) AND (alerts.archived <> 'T'));", 0.010937213897705078)]
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6z13PTcZ5io/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6z13PTcZ5io/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Doesn't the database take care of that? I mean isn't db session handling inside a transaction anyway?
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6z13PTcZ5io/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.