[FIX] gamification: prohibitive record rule processing with many users/goals
authorOlivier Dony <odo@openerp.com>
Wed, 13 Aug 2014 11:26:22 +0000 (13:26 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 13 Aug 2014 11:47:50 +0000 (13:47 +0200)
commit7aa0376f3ec6e7e8bf1c4fb6fb5581a6f18f985e
tree60b61645c117972532dcc207a1924745a7d00447
parent591326c54e8e5cf9acf3fcaaef8f76b0cbb6062c
[FIX] gamification: prohibitive record rule processing with many users/goals

Due to the multi-company record rule on gamification.goal,
each access to the Goals menu and each opening of the
Messaging menu (thus calling get_serialised_gamification_summary())
is extremely slow (with several thousands goals/users).

Adding auto_join to the user_id FK on goals makes it much
faster. However it causes crashes when reading the table
because the _order of gamification.goal uses `create_date`,
which becomes ambiguous after the auto_join with res_users.

Solving this can be done by re-implementing _read_flat()
in the ORM using the internal Query object, as in search(),
which takes care of fully-qualifying all column names.

Until this is fixed, a simple workaround is to use
start_date in the _order instead of collision-prone `create_date`.
addons/gamification/models/goal.py
openerp/osv/orm.py