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
Labels
Merge Requests
141
Merge Requests
141
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
cf05aa72
Commit
cf05aa72
authored
Feb 06, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better handling of Pdata object to avoid MemoryError
parent
7dab2ee4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
13 deletions
+21
-13
product/ERP5/mixin/cached_convertable.py
product/ERP5/mixin/cached_convertable.py
+11
-9
product/ERP5Type/patches/OFSPdata.py
product/ERP5Type/patches/OFSPdata.py
+10
-4
No files found.
product/ERP5/mixin/cached_convertable.py
View file @
cf05aa72
...
...
@@ -48,10 +48,11 @@ def hashPdataObject(pdata_object):
to minimize memory footprint.
"""
md5_hash
=
md5
()
next
=
pdata_object
while
next
is
not
None
:
md5_hash
.
update
(
next
.
data
)
next
=
next
.
next
while
pdata_object
is
not
None
:
chunk
=
pdata_object
.
aq_base
md5_hash
.
update
(
chunk
.
data
)
pdata_object
=
chunk
.
next
chunk
.
_p_deactivate
()
return
md5_hash
.
hexdigest
()
class
CachedConvertableMixin
:
...
...
@@ -130,8 +131,9 @@ class CachedConvertableMixin:
size
=
0
elif
isinstance
(
data
,
Pdata
):
cached_value
=
aq_base
(
data
)
conversion_md5
=
hashPdataObject
(
cached_value
)
size
=
len
(
cached_value
)
size
=
str
(
cached_value
)
# not a size but avoids a 'del' statement
conversion_md5
=
md5
(
size
).
hexdigest
()
size
=
len
(
size
)
elif
isinstance
(
data
,
OFSImage
):
cached_value
=
data
conversion_md5
=
md5
(
str
(
data
.
data
)).
hexdigest
()
...
...
@@ -244,10 +246,10 @@ class CachedConvertableMixin:
def
updateContentMd5
(
self
):
"""Update md5 checksum from the original file
"""
data
=
self
.
g
etData
()
if
data
not
in
(
None
,
''
)
:
data
=
self
.
_baseG
etData
()
if
data
:
if
isinstance
(
data
,
Pdata
):
self
.
_setContentMd5
(
hashPdataObject
(
aq_base
(
data
)
))
self
.
_setContentMd5
(
hashPdataObject
(
data
))
else
:
self
.
_setContentMd5
(
md5
(
data
).
hexdigest
())
# Reindex is useless
else
:
...
...
product/ERP5Type/patches/OFSPdata.py
View file @
cf05aa72
...
...
@@ -28,12 +28,9 @@
##############################################################################
from
OFS.Image
import
Pdata
"""
This patch add a getLastPdata method to return the last Pdata element
of a Pdata
"""
def
getLastPdata
(
self
):
"""Return the last Pdata chunk"""
next
=
self
.
next
while
next
is
not
None
:
...
...
@@ -42,3 +39,12 @@ def getLastPdata(self):
return
self
Pdata
.
getLastPdata
=
getLastPdata
def
__nonzero__
(
self
):
while
not
self
.
data
:
self
=
self
.
next
if
self
is
None
:
return
False
return
True
Pdata
.
__nonzero__
=
__nonzero__
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