Commit 1004c3ec authored by Lucas Carvalho's avatar Lucas Carvalho

Performance improvement: download files does not kill Zope.

Shacache instance is now able to provide big file without getting killed
by the OS, due a memory leak.

Desactivating the previous object is an approach to send the data without
overloading the RAM Memory.
parent 0d2f381b
......@@ -107,3 +107,43 @@ def WebSection_putFactory(self, name, typ, body):
.WebSite_publishDocumentByActivity()
return document
def File_viewAsWeb(self):
"""
Make possible to send the file data to the client without consume the
RAM memory.
"""
RESPONSE = self.REQUEST.RESPONSE
RESPONSE.setHeader('Content-Type', self.getContentType())
RESPONSE.setHeader('Content-Length', self.getSize())
RESPONSE.setHeader('Accept-Ranges', 'bytes')
# If the file is not a Pdata, we should return the data directly.
data=self.data
if isinstance(data, str):
RESPONSE.setBase(None)
return data
# Once the object is PData type,
# we must iterate and send chunk by chunk.
while data is not None:
# Break!! If the channel is closed.
# if the client side stops the connection brutally
# the server side should stop.
if RESPONSE.stdout._channel.closed:
break
# Send data to the client.
RESPONSE.write(data.data)
# Load next object.
next_data = data.next
# Desactivate the object, make sure that this object content
# is not loaded in RAM memory.
data._p_deactivate()
# Set the new data.
data=next_data
return ''
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_function</string> </key>
<value> <string>File_viewAsWeb</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>ShaCache</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>File_viewAsWeb</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
45
\ No newline at end of file
46
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment