From: Maurits v. R. <svn...@pl...> - 2011-08-12 22:37:35
|
Author: maurits Date: Fri Aug 12 22:35:57 2011 New Revision: 243402 Modified: collective.depositbox/trunk/collective/depositbox/TODO.txt collective.depositbox/trunk/collective/depositbox/adapter.py collective.depositbox/trunk/collective/depositbox/store.py Log: Make it possible to configure the purge days and max age. Modified: collective.depositbox/trunk/collective/depositbox/TODO.txt ============================================================================== --- collective.depositbox/trunk/collective/depositbox/TODO.txt (original) +++ collective.depositbox/trunk/collective/depositbox/TODO.txt Fri Aug 12 22:35:57 2011 @@ -12,4 +12,3 @@ should work. Did some performance tests: PersistentMapping is slightly faster for larger stored amounts (thousands); OOBTree is 20% faster for smaller amounts (10). - Modified: collective.depositbox/trunk/collective/depositbox/adapter.py ============================================================================== --- collective.depositbox/trunk/collective/depositbox/adapter.py (original) +++ collective.depositbox/trunk/collective/depositbox/adapter.py Fri Aug 12 22:35:57 2011 @@ -5,6 +5,7 @@ from zope.annotation.interfaces import IAnnotations from zope.annotation.interfaces import IAttributeAnnotatable from collective.depositbox.store import Box +from collective.depositbox import config from collective.depositbox.interfaces import IDepositBox logger = logging.getLogger('collective.depositbox') @@ -16,13 +17,15 @@ implements(IDepositBox) adapts(IAttributeAnnotatable) ANNO_KEY = 'collective.depositbox' + max_age = config.MAX_AGE + purge_days = config.PURGE_DAYS def __init__(self, context): self.context = context annotations = IAnnotations(context) self.box = annotations.get(self.ANNO_KEY, None) if self.box is None: - annotations[self.ANNO_KEY] = Box() + annotations[self.ANNO_KEY] = Box(self.max_age, self.purge_days) self.box = annotations[self.ANNO_KEY] def put(self, value, token=None): Modified: collective.depositbox/trunk/collective/depositbox/store.py ============================================================================== --- collective.depositbox/trunk/collective/depositbox/store.py (original) +++ collective.depositbox/trunk/collective/depositbox/store.py Fri Aug 12 22:35:57 2011 @@ -5,9 +5,9 @@ from persistent.mapping import PersistentMapping from zope.interface import implements +from collective.depositbox import config from collective.depositbox.interfaces import IDepositBox -MAX_ID = 2 ** 31 logger = logging.getLogger('collective.depositbox') @@ -23,15 +23,11 @@ class Box(Persistent): implements(IDepositBox) - # Maximum age of items in days (you can specify 1.0/24 for one - # hour if you want). - max_age = 7 - # How often should the box be purged? - purge_days = 1 - - def __init__(self): + def __init__(self, max_age=config.MAX_AGE, purge_days=config.PURGE_DAYS): self.data = PersistentMapping() self._last_purge = int(time.time()) + self.max_age = max_age + self.purge_days = purge_days def _generate_new_id(self): """Generate new id. |