Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Laurent S
erp5
Commits
31b4bb58
Commit
31b4bb58
authored
Apr 26, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CMFActivity: small optimizations
parent
ba6521c4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
28 deletions
+41
-28
product/CMFActivity/Activity/SQLBase.py
product/CMFActivity/Activity/SQLBase.py
+20
-22
product/CMFActivity/Activity/SQLDict.py
product/CMFActivity/Activity/SQLDict.py
+2
-4
product/CMFActivity/skins/activity/SQLDict_reserveDuplicatedLineList.zsql
...ity/skins/activity/SQLDict_reserveDuplicatedLineList.zsql
+2
-2
product/CMFActivity/tests/testCMFActivity.py
product/CMFActivity/tests/testCMFActivity.py
+17
-0
No files found.
product/CMFActivity/Activity/SQLBase.py
View file @
31b4bb58
...
...
@@ -203,30 +203,27 @@ class SQLBase(Queue):
processing_node
=
processing_node
,
limit
=
limit
,
group_method_id
=
group_method_id
)
if
l
en
(
line_list
)
:
if
l
ine_list
:
self
.
_log
(
TRACE
,
'Reserved messages: %r'
%
[
x
.
uid
for
x
in
line_list
])
return
line_list
def
getDuplicateMessageUidList
(
line
):
uid_list
=
self
.
getDuplicateMessageUidList
(
activity_tool
=
activity_tool
,
line
=
line
,
processing_node
=
processing_node
)
if
len
(
uid_list
)
:
if
uid_list
:
self
.
_log
(
TRACE
,
'Reserved duplicate messages: %r'
%
(
uid_list
,
))
return
uid_list
now_date
=
self
.
getNow
(
activity_tool
)
message_list
=
[]
group_method_id
=
None
try
:
result
=
getReservedMessageList
(
limit
=
1
)
uid_to_duplicate_uid_list_dict
=
{}
if
len
(
result
)
>
0
:
try
:
result
=
getReservedMessageList
(
1
)
if
result
:
line
=
result
[
0
]
uid
=
line
.
uid
m
=
self
.
loadMessage
(
line
.
message
,
uid
=
uid
,
line
=
line
)
message_list
.
append
(
m
)
message_list
=
[
m
]
uid_to_duplicate_uid_list_dict
[
uid
]
=
getDuplicateMessageUidList
(
line
)
group_method_id
=
line
.
group_method_id
activity_tool
.
SQLBase_processMessage
(
table
=
self
.
sql_table
,
uid
=
[
uid
])
uid_to_duplicate_uid_list_dict
.
setdefault
(
uid
,
[])
\
.
extend
(
getDuplicateMessageUidList
(
line
))
if
group_method_id
!=
'
\
0
'
:
# Count the number of objects to prevent too many objects.
cost
=
m
.
activity_kw
.
get
(
'group_method_cost'
,
.
01
)
...
...
@@ -238,9 +235,9 @@ class SQLBase(Queue):
if
limit
>
1
:
# <=> cost * count < 1
cost
*=
count
# Retrieve objects which have the same group method.
result
=
getReservedMessageList
(
limit
=
limit
,
group_method_id
=
group_method_id
)
path_and_method_id_dict
=
{
}
result
=
getReservedMessageList
(
limit
,
group_method_id
)
if
self
.
merge_duplicate
:
path_and_method_id_dict
=
{(
line
.
path
,
line
.
method_id
):
uid
}
unreserve_uid_list
=
[]
for
line
in
result
:
if
line
.
uid
==
uid
:
...
...
@@ -254,12 +251,11 @@ class SQLBase(Queue):
key
=
line
.
path
,
line
.
method_id
original_uid
=
path_and_method_id_dict
.
get
(
key
)
if
original_uid
is
not
None
:
uid_to_duplicate_uid_list_dict
.
setdefault
(
original_uid
,
[])
\
.
append
(
line
.
uid
)
uid_to_duplicate_uid_list_dict
[
original_uid
].
append
(
line
.
uid
)
continue
path_and_method_id_dict
[
key
]
=
line
.
uid
uid_to_duplicate_uid_list_dict
.
setdefault
(
line
.
uid
,
[])
\
.
extend
(
getDuplicateMessageUidList
(
line
)
)
uid_to_duplicate_uid_list_dict
[
line
.
uid
]
=
\
getDuplicateMessageUidList
(
line
)
if
cost
<
1
:
m
=
self
.
loadMessage
(
line
.
message
,
uid
=
line
.
uid
,
line
=
line
)
cost
+=
len
(
m
.
getObjectList
(
activity_tool
))
*
\
...
...
@@ -275,19 +271,21 @@ class SQLBase(Queue):
return
message_list
,
group_method_id
,
uid_to_duplicate_uid_list_dict
except
:
self
.
_log
(
WARNING
,
'Exception while reserving messages.'
)
if
len
(
message_list
):
to_free_uid_list
=
[
m
.
uid
for
m
in
message_list
]
if
uid_to_duplicate_uid_list_dict
:
to_free_uid_list
=
uid_to_duplicate_uid_list_dict
.
keys
()
for
uid_list
in
uid_to_duplicate_uid_list_dict
.
itervalues
():
to_free_uid_list
+=
uid_list
try
:
self
.
makeMessageListAvailable
(
activity_tool
=
activity_tool
,
uid_list
=
to_free_uid_list
)
except
:
self
.
_log
(
ERROR
,
'Failed to free messages: %r'
%
to_free_uid_list
)
else
:
if
len
(
to_free_uid_list
)
:
if
to_free_uid_list
:
self
.
_log
(
TRACE
,
'Freed messages %r'
%
to_free_uid_list
)
else
:
self
.
_log
(
TRACE
,
'(no message was reserved)'
)
return
[],
None
,
{}
return
[],
None
,
uid_to_duplicate_uid_list_dict
def
_abort
(
self
):
try
:
...
...
product/CMFActivity/Activity/SQLDict.py
View file @
31b4bb58
...
...
@@ -121,11 +121,9 @@ class SQLDict(SQLBase):
group_method_id
=
line
.
group_method_id
,
)
uid_list
=
[
x
.
uid
for
x
in
result
]
if
len
(
uid_list
)
:
if
uid_list
:
activity_tool
.
SQLDict_reserveDuplicatedLineList
(
processing_node
=
processing_node
,
uid_list
=
uid_list
)
processing_node
=
processing_node
,
uid
=
uid_list
)
else
:
# Release locks
activity_tool
.
SQLDict_commit
()
...
...
product/CMFActivity/skins/activity/SQLDict_reserveDuplicatedLineList.zsql
View file @
31b4bb58
...
...
@@ -9,13 +9,13 @@ class_file:
</dtml-comment>
<params>
processing_node
uid
_list
uid
</params>
UPDATE
message
SET
processing_node=<dtml-sqlvar processing_node type="int">
WHERE
uid IN (<dtml-in uid_list><dtml-sqlvar sequence-item type="int"><dtml-if sequence-end><dtml-else>, </dtml-if></dtml-in>)
<dtml-sqltest uid type="int" multiple>
<dtml-var sql_delimiter>
COMMIT
product/CMFActivity/tests/testCMFActivity.py
View file @
31b4bb58
...
...
@@ -3650,6 +3650,23 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
finally
:
del
obj
.
__class__
.
doSomething
def
test_duplicateGroupedMessage
(
self
):
activity_tool
=
self
.
portal
.
portal_activities
obj
=
activity_tool
.
newActiveProcess
()
obj
.
reindexObject
(
activate_kw
=
{
'tag'
:
'foo'
,
'after_tag'
:
'bar'
})
transaction
.
commit
()
invoked
=
[]
def
invokeGroup
(
self
,
*
args
):
invoked
.
append
(
len
(
args
[
1
]))
return
ActivityTool_invokeGroup
(
self
,
*
args
)
ActivityTool_invokeGroup
=
activity_tool
.
__class__
.
invokeGroup
try
:
activity_tool
.
__class__
.
invokeGroup
=
invokeGroup
self
.
tic
()
finally
:
activity_tool
.
__class__
.
invokeGroup
=
ActivityTool_invokeGroup
self
.
assertEqual
(
invoked
,
[
1
])
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestCMFActivity
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment