Browse Source

Add cron to sync data to old column + improve exception logging

pull/144/head
Matthieu Dietrich 10 years ago
parent
commit
e66fab88e6
  1. 6
      base_login_date_improvement/__openerp__.py
  2. 24
      base_login_date_improvement/cron.xml
  3. 21
      base_login_date_improvement/res_users.py

6
base_login_date_improvement/__openerp__.py

@ -28,12 +28,14 @@ Module to separate the login date from res.users; on long transactions,
"re-logging" by opening a new tab changes the current res.user row,
which creates concurrency issues with PostgreSQL in the first transaction.
This creates a new table and a function field to avoid this.
This creates a new table and a function field to avoid this. In order to
avoid breaking modules which access via SQL the login_date column, a cron
(inactive by default) can be used to sync data.
""",
"website": "http://camptocamp.com",
"depends": ['base'],
"data": ['security/ir.model.access.csv',
],
'cron.xml'],
"auto_install": False,
"installable": True
}

24
base_login_date_improvement/cron.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding='UTF-8'?>
<openerp>
<data>
<!--
This cron can be used to synchronize the login dates
back to the res.users SQL table, since some modules
(ex: gamification, auth_openid) use a SQL request
to read the data. Otherwise, it should stay inactive.
-->
<record model="ir.cron" id="cron_res_users_login">
<field name="name">Synchronize login dates in res.users</field>
<field name="interval_number">1</field>
<field name="active" eval="False"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'res.users.login'"/>
<field name="function" eval="'cron_sync_login_date'"/>
<field name="args" eval="'()'"/>
</record>
</data>
</openerp>

21
base_login_date_improvement/res_users.py

@ -39,9 +39,23 @@ class ResUsersLogin(orm.Model):
_sql_constraints = [
('user_id_unique',
'unique(user_id)',
'The user can only have one login line !')
'The user can only have one login line!')
]
# Cron method
def cron_sync_login_date(self, cr, uid, context=None):
# Simple SQL query to update the original login_date column.
try:
cr.execute("UPDATE res_users SET login_date = "
"(SELECT login_dt FROM res_users_login "
"WHERE res_users_login.user_id = res_users.id)")
cr.commit()
except Exception as e:
cr.rollback()
_logger.exception('Could not synchronize login dates: %s', e)
return True
class ResUsers(orm.Model):
@ -114,8 +128,9 @@ class ResUsers(orm.Model):
"for db:%s login:%s",
db, login, exc_info=True)
cr.rollback()
except Exception:
pass
except Exception as e:
_logger.exception('Login exception: %s', e)
user_id = False
finally:
cr.close()

Loading…
Cancel
Save