[Zope] ZODB question, again
Chris Withers
chrisw@nipltd.com
Fri, 17 Mar 2000 09:48:13 +0000
Hi,
Wasn't it generally agreed that storing a counter in a ZODB was a bad idea 'cos of the high number
of refreshes, and hence the number of transactions stored in DB?
Basically, because of the undo/rollback capability of ZODB, the data.fs grows rapidly if you use it
to do counter-type things.
Or an I wrong?
Chris
Jonothan Farr wrote:
>
> I would implement this whole thing as a Python product and avoid mucking around
> directly with the persistence machinery altogether. This would allow you to add
> a Counter object anywhere in the Zope tree.
>
> import OFS, Persistence
>
> class Counter(OFS.SimpleItem.Item, Persistence.Persistent):
>
> def __init__(self, id, title):
> self.id = id
> self.title = title
> self.counters = {}
>
> def Count(self, name):
> if not self.counters.has_key(name):
> self.counters[name] = 0
> v = self.counters[name] + 1
> self.counters[name] = v
> return v
>
> manage_addCounterForm=HTMLFile('methodAdd', globals())
>
> def manage_addCounter(self, id, title, REQUEST=None):
> ob = Counter(id, title)
> self._setObject(id, ob)
> return self.manage_main(self, REQUEST)
>
> Add a Counter call 'counter' to a folder, then call:
>
> <dtml-var "counter.Count('chickens')">
>
> -jfarr
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Hi! I'm a signature virus.
> Copy me into your .sig to join the fun!
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )