[Erp5-report] r12139 - in /erp5/trunk/products/ERP5/Document: Document.py File.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Jan 18 18:47:27 CET 2007
Author: romain
Date: Thu Jan 18 18:47:24 2007
New Revision: 12139
URL: http://svn.erp5.org?rev=12139&view=rev
Log:
By JPS.
Fix caching issue with converted image.
Restore _setFile virtual accessor.
Modified:
erp5/trunk/products/ERP5/Document/Document.py
erp5/trunk/products/ERP5/Document/File.py
Modified: erp5/trunk/products/ERP5/Document/Document.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Document.py?rev=12139&r1=12138&r2=12139&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Document.py (original)
+++ erp5/trunk/products/ERP5/Document/Document.py Thu Jan 18 18:47:24 2007
@@ -30,6 +30,8 @@
from operator import add
from AccessControl import ClassSecurityInfo, getSecurityManager
+from Acquisition import aq_base
+from Globals import PersistentMapping
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.XMLObject import XMLObject
@@ -58,11 +60,11 @@
* Implement ZODB BLOB
"""
# time of generation of various formats
- _cached_time = {}
+ _cached_time = None # Defensive programming - prevent caching to RAM
# generated files (cache)
- _cached_data = {}
+ _cached_data = None # Defensive programming - prevent caching to RAM
# mime types for cached formats XXX to be refactored
- _cached_mime = {}
+ _cached_mime = None # Defensive programming - prevent caching to RAM
# Declarative security
security = ClassSecurityInfo()
@@ -74,15 +76,26 @@
Clear cache (invoked by interaction workflow upon file upload
needed here to overwrite class attribute with instance attrs
"""
- self._cached_time = {}
- self._cached_data = {}
- self._cached_mime = {}
+ self._cached_time = PersistentMapping()
+ self._cached_data = PersistentMapping()
+ self._cached_mime = PersistentMapping()
+
+ security.declareProtected(Permissions.View, 'updateConversionCache')
+ def updateConversionCache(self):
+ aself = aq_base(self)
+ if not hasattr(aself, '_cached_time'):
+ self._cached_time = PersistentMapping()
+ if not hasattr(aself, '_cached_data'):
+ self._cached_data = PersistentMapping()
+ if not hasattr(aself, '_cached_mime'):
+ self._cached_mime = PersistentMapping()
security.declareProtected(Permissions.View, 'hasConversion')
def hasConversion(self, **format):
"""
Checks whether we have a version in this format
"""
+ self.updateConversionCache()
return self._cached_data.has_key(makeSortedTuple(format))
security.declareProtected(Permissions.View, 'getCacheTime')
@@ -90,11 +103,13 @@
"""
Checks when if ever was the file produced
"""
+ self.updateConversionCache()
return self._cached_time.get(makeSortedTuple(format), 0)
security.declareProtected(Permissions.ModifyPortalContent, 'updateConversion')
def updateConversion(self, **format):
- self._cached_time[makeSortedTuple(format)] = DateTime()
+ self.updateConversionCache()
+ self._cached_time[makeSortedTuple(format)] = DateTime()
security.declareProtected(Permissions.ModifyPortalContent, 'setConversion')
def setConversion(self, data, mime=None, **format):
@@ -102,6 +117,7 @@
Saves a version of the document in a given format; records mime type
and conversion time (which is right now).
"""
+ self.updateConversionCache()
tformat = makeSortedTuple(format)
if mime is not None:
self._cached_mime[tformat] = mime
@@ -121,6 +137,7 @@
so that it does it all by itself; this'd eliminate the need for setConversion public method)
XXX-BG: I'm not sure now what I meant by this...
"""
+ self.updateConversionCache()
tformat = makeSortedTuple(format)
return self._cached_mime.get(tformat, ''), self._cached_data.get(tformat, '')
@@ -129,6 +146,7 @@
"""
Get cache details as string (for debugging)
"""
+ self.updateConversionCache()
s = 'CACHE INFO:<br/><table><tr><td>format</td><td>size</td><td>time</td><td>is changed</td></tr>'
for f in self._cached_time.keys():
t = self._cached_time[f]
Modified: erp5/trunk/products/ERP5/Document/File.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/File.py?rev=12139&r1=12138&r2=12139&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/File.py (original)
+++ erp5/trunk/products/ERP5/Document/File.py Thu Jan 18 18:47:24 2007
@@ -107,7 +107,7 @@
file = kw.get('file')
precondition = kw.get('precondition')
if self._isNotEmpty(file):
- CMFFile._edit(self, precondition=precondition, file=file)
+ self._setFile(file, precondition=precondition)
del kw['file']
Base._edit(self, **kw)
@@ -141,6 +141,7 @@
getcontentlength = get_size
+ # File management virtual accessor
security.declareProtected(Permissions.View, 'hasFile')
def hasFile(self):
"""
@@ -150,6 +151,15 @@
if getattr(self,'data', _marker) is not _marker: # XXX-JPS - use propertysheet accessors
return getattr(self,'data') is not None
return False
+
+ def _setFile(self, data, precondition=None):
+ self.clearConversionCache()
+ CMFFile._edit(self, precondition=precondition, file=data)
+
+ security.declareProtected(Permissions.ModifyPortalContent,'setFile')
+ def setFile(self, data, precondition=None):
+ self._setFile(data, precondition=precondition)
+ self.reindexObject()
security.declarePrivate('_unpackData')
def _unpackData(self,data):
@@ -179,6 +189,7 @@
security.declareProtected(Permissions.ModifyPortalContent,'PUT')
def PUT(self,REQUEST,RESPONSE):
+ self.clearConversionCache()
CMFFile.PUT(self,REQUEST,RESPONSE)
self.DMS_ingestFile(fname=self.getId()) # XXX-JPS we should call here Document_discoverMetadata
# with the filename as parameter
More information about the Erp5-report
mailing list