[IMP] gamification: performance improvement on the goal computation
authorMartin Trigaux <mat@openerp.com>
Tue, 6 May 2014 09:37:16 +0000 (11:37 +0200)
committerMartin Trigaux <mat@openerp.com>
Tue, 6 May 2014 09:37:16 +0000 (11:37 +0200)
Removing the inheritance to mail.thread will avoid posting message at creation and other tracking mechanism at each write. Updating a challenge with a large number of users will be significantly faster.

bzr revid: mat@openerp.com-20140506093716-xvpe1n2ase2zix0v

addons/gamification/models/challenge.py
addons/gamification/models/goal.py
addons/gamification/views/goal.xml

index ecb4c49..a6c467f 100644 (file)
@@ -355,10 +355,13 @@ class gamification_challenge(osv.Model):
                 if write_op:
                     self.write(cr, uid, [challenge.id], {'user_ids': write_op}, context=context)
 
-                if to_remove_ids:
-                    self.message_unsubscribe_users(cr, uid, [challenge.id], to_remove_ids, context=None)
-                if to_add_ids:
-                    self.message_subscribe_users(cr, uid, [challenge.id], to_add_ids, context=context)
+                if challenge.report_message_frequency != 'never':
+                    if to_remove_ids:
+                        self.message_unsubscribe_users(cr, uid, [challenge.id], to_remove_ids, context=context)
+                    if to_add_ids:
+                        self.message_subscribe_users(cr, uid, [challenge.id], to_add_ids, context=context)
+                else:
+                    self.message_unsubscribe_users(cr, uid, [challenge.id], old_user_ids, context=context)
 
         return True
 
index af9a763..7fcf8e5 100644 (file)
@@ -138,7 +138,6 @@ class gamification_goal(osv.Model):
 
     _name = 'gamification.goal'
     _description = 'Gamification goal instance'
-    _inherit = 'mail.thread'
 
     def _get_completion(self, cr, uid, ids, field_name, arg, context=None):
         """Return the percentage of completeness of the goal, between 0 and 100"""
@@ -226,8 +225,7 @@ class gamification_goal(osv.Model):
                 temp_obj = self.pool.get('email.template')
                 template_id = self.pool['ir.model.data'].get_object(cr, uid, 'gamification', 'email_template_goal_reminder', context)
                 body_html = temp_obj.render_template(cr, uid, template_id.body_html, 'gamification.goal', goal.id, context=context)
-
-                self.message_post(cr, uid, goal.id, body=body_html, partner_ids=[goal.user_id.partner_id.id], context=context, subtype='mail.mt_comment')
+                self.pool['mail.thread'].message_post(cr, uid, 0, body=body_html, partner_ids=[goal.user_id.partner_id.id], context=context, subtype='mail.mt_comment')
                 return {'to_update': True}
         return {}
 
index 528d5db..8844674 100644 (file)
                             </group>
                         </group>
                     </sheet>
-                    <div class="oe_chatter">
-                        <field name="message_follower_ids" widget="mail_followers"/>
-                        <field name="message_ids" widget="mail_thread"/>
-                    </div>
                 </form>
             </field>
         </record>