Merge lp:~dreis-pt/project-service/7.0-fixcounters into lp:~project-core-editors/project-service/trunk

Proposed by Daniel Reis
Status: Needs review
Proposed branch: lp:~dreis-pt/project-service/7.0-fixcounters
Merge into: lp:~project-core-editors/project-service/trunk
Diff against target: 128 lines (+107/-0)
4 files modified
.bzrignore (+1/-0)
project_issue_fixcount/__init__.py (+2/-0)
project_issue_fixcount/__openerp__.py (+35/-0)
project_issue_fixcount/project.py (+69/-0)
To merge this branch: bzr merge lp:~dreis-pt/project-service/7.0-fixcounters
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Information
Stefan Rijnhart (Opener) Pending
Review via email: mp+219558@code.launchpad.net

Description of the change

In v7, Project kanban can take forever to load, due to inefficient implementation of the counters (Issues, Tasks and Documents).
AFAIK it has been fixed in v8, so this is mostly a backport for that work.

To post a comment you must log in.
41. By Daniel Reis

New project_issue_fixcounter module

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Daniel, don't you think this fits best on OCB?

Regards.

review: Needs Information
Revision history for this message
Daniel Reis (dreis-pt) wrote :

I did hesitate on that. Let's ask for Stephan's opinion on it.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I suppose that he said that changes are too deep for OCB, and maybe he's right, but I don't think v7 is going to receive too much changes on this part to produce conflicts.

Let's see what he says.

Regards.

Revision history for this message
Daniel Reis (dreis-pt) wrote :

This project is now hosted on https://github.com/OCA/project-service. Please move your proposal there.
This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

Unmerged revisions

41. By Daniel Reis

New project_issue_fixcounter module

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-06-27 14:33:04 +0000
3+++ .bzrignore 2014-05-14 16:19:44 +0000
4@@ -1,1 +1,2 @@
5 *.pyc
6+project_issue_fixcount/.ropeproject
7
8=== added directory 'project_issue_fixcount'
9=== added file 'project_issue_fixcount/__init__.py'
10--- project_issue_fixcount/__init__.py 1970-01-01 00:00:00 +0000
11+++ project_issue_fixcount/__init__.py 2014-05-14 16:19:44 +0000
12@@ -0,0 +1,2 @@
13+# -*- coding: utf-8 -*-
14+import project
15
16=== added file 'project_issue_fixcount/__openerp__.py'
17--- project_issue_fixcount/__openerp__.py 1970-01-01 00:00:00 +0000
18+++ project_issue_fixcount/__openerp__.py 2014-05-14 16:19:44 +0000
19@@ -0,0 +1,35 @@
20+# -*- coding: utf-8 -*-
21+##############################################################################
22+#
23+# Copyright (C) 2014 Daniel Reis
24+#
25+# This program is free software: you can redistribute it and/or modify
26+# it under the terms of the GNU Affero General Public License as
27+# published by the Free Software Foundation, either version 3 of the
28+# License, or (at your option) any later version.
29+#
30+# This program is distributed in the hope that it will be useful,
31+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+# GNU Affero General Public License for more details.
34+#
35+# You should have received a copy of the GNU Affero General Public License
36+# along with this program. If not, see <http://www.gnu.org/licenses/>.
37+#
38+##############################################################################
39+{
40+ 'name': 'Backport more efficient Project counters',
41+ 'version': '1.0',
42+ "category": "Project Management",
43+ 'description': """\
44+Fix performance issues with v7 Project counters.
45+Will probably be unnecessary in v8.
46+""",
47+ 'author': 'Daniel Reis',
48+ 'website': '',
49+ 'depends': [
50+ 'project_issue',
51+ ],
52+ 'data': [],
53+ 'installable': True,
54+}
55
56=== added file 'project_issue_fixcount/project.py'
57--- project_issue_fixcount/project.py 1970-01-01 00:00:00 +0000
58+++ project_issue_fixcount/project.py 2014-05-14 16:19:44 +0000
59@@ -0,0 +1,69 @@
60+# -*- coding: utf-8 -*-
61+##############################################################################
62+#
63+# Copyright (C) 2014 Daniel Reis
64+#
65+# This program is free software: you can redistribute it and/or modify
66+# it under the terms of the GNU Affero General Public License as
67+# published by the Free Software Foundation, either version 3 of the
68+# License, or (at your option) any later version.
69+#
70+# This program is distributed in the hope that it will be useful,
71+# but WITHOUT ANY WARRANTY; without even the implied warranty of
72+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+# GNU Affero General Public License for more details.
74+#
75+# You should have received a copy of the GNU Affero General Public License
76+# along with this program. If not, see <http://www.gnu.org/licenses/>.
77+#
78+##############################################################################
79+
80+from openerp.osv import fields, orm
81+
82+
83+class Project(orm.Model):
84+ _inherit = 'project.project'
85+
86+ def _task_count(self, cr, uid, ids, field_name, arg, context=None):
87+ "Backport from v8"
88+ res = {}
89+ for tasks in self.browse(cr, uid, ids, context):
90+ res[tasks.id] = len(tasks.task_ids)
91+ return res
92+
93+ def _issue_count(self, cr, uid, ids, field_name, arg, context=None):
94+ "Backport from v8"
95+ Issue = self.pool['project.issue']
96+ return {
97+ project_id: Issue.search_count(
98+ cr, uid,
99+ [('project_id', '=', project_id),
100+ ('stage_id.fold', '=', False)],
101+ context=context)
102+ for project_id in ids
103+ }
104+
105+ def _get_attached_docs(self, cr, uid, ids, field_name, arg, context):
106+ "We don't count documents to improve performance"
107+ res = {}
108+ # attachment = self.pool.get('ir.attachment')
109+ # task = self.pool.get('project.task')
110+ for id in ids:
111+ # project_attachments = attachment.search(cr, uid, [('res_model', '=', 'project.project'), ('res_id', '=', id)], context=context, count=True)
112+ # task_ids = task.search(cr, uid, [('project_id', '=', id)], context=context)
113+ # task_attachments = attachment.search(cr, uid, [('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)], context=context, count=True)
114+ res[id] = 0 # (project_attachments or 0) + (task_attachments or 0)
115+ return res
116+
117+ _columns = {
118+ 'task_count': fields.function(
119+ _task_count, type='integer', string="Tasks",),
120+ 'task_ids': fields.one2many(
121+ 'project.task', 'project_id',
122+ domain=[('stage_id.fold', '=', False)]),
123+ 'issue_count': fields.function(
124+ _issue_count, string='# Issues', type='integer'),
125+ 'doc_count': fields.function(
126+ _get_attached_docs,
127+ string="Number of documents attached", type='integer'),
128+ }

Subscribers

People subscribed via source and target branches