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
Yoji Takeuchi
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):
...
@@ -48,10 +48,11 @@ def hashPdataObject(pdata_object):
to minimize memory footprint.
to minimize memory footprint.
"""
"""
md5_hash
=
md5
()
md5_hash
=
md5
()
next
=
pdata_object
while
pdata_object
is
not
None
:
while
next
is
not
None
:
chunk
=
pdata_object
.
aq_base
md5_hash
.
update
(
next
.
data
)
md5_hash
.
update
(
chunk
.
data
)
next
=
next
.
next
pdata_object
=
chunk
.
next
chunk
.
_p_deactivate
()
return
md5_hash
.
hexdigest
()
return
md5_hash
.
hexdigest
()
class
CachedConvertableMixin
:
class
CachedConvertableMixin
:
...
@@ -130,8 +131,9 @@ class CachedConvertableMixin:
...
@@ -130,8 +131,9 @@ class CachedConvertableMixin:
size
=
0
size
=
0
elif
isinstance
(
data
,
Pdata
):
elif
isinstance
(
data
,
Pdata
):
cached_value
=
aq_base
(
data
)
cached_value
=
aq_base
(
data
)
conversion_md5
=
hashPdataObject
(
cached_value
)
size
=
str
(
cached_value
)
# not a size but avoids a 'del' statement
size
=
len
(
cached_value
)
conversion_md5
=
md5
(
size
).
hexdigest
()
size
=
len
(
size
)
elif
isinstance
(
data
,
OFSImage
):
elif
isinstance
(
data
,
OFSImage
):
cached_value
=
data
cached_value
=
data
conversion_md5
=
md5
(
str
(
data
.
data
)).
hexdigest
()
conversion_md5
=
md5
(
str
(
data
.
data
)).
hexdigest
()
...
@@ -244,10 +246,10 @@ class CachedConvertableMixin:
...
@@ -244,10 +246,10 @@ class CachedConvertableMixin:
def
updateContentMd5
(
self
):
def
updateContentMd5
(
self
):
"""Update md5 checksum from the original file
"""Update md5 checksum from the original file
"""
"""
data
=
self
.
g
etData
()
data
=
self
.
_baseG
etData
()
if
data
not
in
(
None
,
''
)
:
if
data
:
if
isinstance
(
data
,
Pdata
):
if
isinstance
(
data
,
Pdata
):
self
.
_setContentMd5
(
hashPdataObject
(
aq_base
(
data
)
))
self
.
_setContentMd5
(
hashPdataObject
(
data
))
else
:
else
:
self
.
_setContentMd5
(
md5
(
data
).
hexdigest
())
# Reindex is useless
self
.
_setContentMd5
(
md5
(
data
).
hexdigest
())
# Reindex is useless
else
:
else
:
...
...
product/ERP5Type/patches/OFSPdata.py
View file @
cf05aa72
...
@@ -28,12 +28,9 @@
...
@@ -28,12 +28,9 @@
##############################################################################
##############################################################################
from
OFS.Image
import
Pdata
from
OFS.Image
import
Pdata
"""
This patch add a getLastPdata method to return the last Pdata element
of a Pdata
"""
def
getLastPdata
(
self
):
def
getLastPdata
(
self
):
"""Return the last Pdata chunk"""
next
=
self
.
next
next
=
self
.
next
while
next
is
not
None
:
while
next
is
not
None
:
...
@@ -42,3 +39,12 @@ def getLastPdata(self):
...
@@ -42,3 +39,12 @@ def getLastPdata(self):
return
self
return
self
Pdata
.
getLastPdata
=
getLastPdata
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