Commit c0f3f8c8 authored by Jim Fulton's avatar Jim Fulton

Changed to no use sub-transactions unless we have large (> 128K)

images/files that use file-upload.  This makes it easier to use small
images with SQL methods.
parent 11b2a67e
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Image object""" """Image object"""
__version__='$Revision: 1.83 $'[11:-2] __version__='$Revision: 1.84 $'[11:-2]
import Globals, string, struct, content_types import Globals, string, struct, content_types
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
...@@ -98,7 +98,7 @@ from Globals import Persistent ...@@ -98,7 +98,7 @@ from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
from DateTime import DateTime from DateTime import DateTime
StringType=type('')
manage_addFileForm=HTMLFile('imageAdd', globals(),Kind='File',kind='file') manage_addFileForm=HTMLFile('imageAdd', globals(),Kind='File',kind='file')
def manage_addFile(self,id,file,title='',precondition='', content_type='', def manage_addFile(self,id,file,title='',precondition='', content_type='',
...@@ -111,14 +111,11 @@ def manage_addFile(self,id,file,title='',precondition='', content_type='', ...@@ -111,14 +111,11 @@ def manage_addFile(self,id,file,title='',precondition='', content_type='',
self=self.this() self=self.this()
# First, we create the image without data: # First, we create the file without data:
self._setObject(id, File(id,title,'',content_type, precondition)) self._setObject(id, File(id,title,'',content_type, precondition))
# And commit to a sub-transaction: # Now we "upload" the data. By doing this in two steps, we
if Globals.DatabaseVersion=='3': get_transaction().commit(1) # can use a database trick to make the upload more efficient.
# Now we "upload" the data. By commiting the add first, the
# object can use a database trick to make the upload more efficient.
self._getOb(id).manage_upload(file) self._getOb(id).manage_upload(file)
if REQUEST is not None: if REQUEST is not None:
...@@ -260,7 +257,7 @@ class File(Persistent,Implicit,PropertyManager, ...@@ -260,7 +257,7 @@ class File(Persistent,Implicit,PropertyManager,
n=1<<16 n=1<<16
if type(file) is type(''): if type(file) is StringType:
size=len(file) size=len(file)
if size < n: return file, size if size < n: return file, size
return Pdata(file), size return Pdata(file), size
...@@ -270,11 +267,21 @@ class File(Persistent,Implicit,PropertyManager, ...@@ -270,11 +267,21 @@ class File(Persistent,Implicit,PropertyManager,
seek(0,2) seek(0,2)
size=end=file.tell() size=end=file.tell()
if size <= 2*n:
seek(0)
if size < n: return read(size), size
return Pdata(read(size)), size
# Make sure we have an _p_jar, even if we are a new object, by
# doing a sub-transaction commit.
get_transaction().commit(1)
jar=self._p_jar jar=self._p_jar
if size <= 2*n or jar is None or Globals.DatabaseVersion=='2':
if jar is None:
# Ugh
seek(0) seek(0)
if size < n:
return read(size), size
return Pdata(read(size)), size return Pdata(read(size)), size
# Now we're going to build a linked list from back # Now we're going to build a linked list from back
...@@ -363,9 +370,13 @@ def manage_addImage(self, id, file, title='', precondition='', content_type='', ...@@ -363,9 +370,13 @@ def manage_addImage(self, id, file, title='', precondition='', content_type='',
self=self.this() self=self.this()
# First, we create the image without data:
self._setObject(id, Image(id,title,'',content_type, precondition)) self._setObject(id, Image(id,title,'',content_type, precondition))
if Globals.DatabaseVersion=='3': get_transaction().commit(1)
# Now we "upload" the data. By doing this in two steps, we
# can use a database trick to make the upload more efficient.
self._getOb(id).manage_upload(file) self._getOb(id).manage_upload(file)
if REQUEST is not None: if REQUEST is not None:
try: url=self.DestinationURL() try: url=self.DestinationURL()
except: url=REQUEST['URL1'] except: url=REQUEST['URL1']
......
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