source: WAeUP_SRP/trunk/patches/PatchZCatalogCatalogUpdateMetadata.py @ 17305

Last change on this file since 17305 was 3673, checked in by jens, 16 years ago
  • unclutter package by moving all patch files into a dedicated subfolder and importing it.
  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1from BTrees.IOBTree import IOBTree
2from random import randint
3def updateMetadata(self, object, uid):
4    """ Given an object and a uid, update the column data for the
5    uid with the object data iff the object has changed """
6    data = self.data
7    index = self.uids.get(uid, None)
8    newDataRecord = self.recordify(object)
9
10    if index is None:
11        if type(data) is IOBTree:
12            # New style, get random id
13
14            index=getattr(self, '_v_nextid', 0)
15            if index % 4000 == 0:
16                index = randint(-2000000000, 2000000000)
17            while not data.insert(index, newDataRecord):
18                index = randint(-2000000000, 2000000000)
19
20            # We want ids to be somewhat random, but there are
21            # advantages for having some ids generated
22            # sequentially when many catalog updates are done at
23            # once, such as when reindexing or bulk indexing.
24            # We allocate ids sequentially using a volatile base,
25            # so different threads get different bases. This
26            # further reduces conflict and reduces churn in
27            # here and it result sets when bulk indexing.
28            self._v_nextid=index+1
29        else:
30            if data:
31                # find the next available unique id
32                index = data.keys()[-1] + 1
33            else:
34                index=0
35            # meta_data is stored as a tuple for efficiency
36            data[index] = newDataRecord
37    else:
38        #if True or data.get(index, 0) != newDataRecord:
39        data[index] = newDataRecord
40    return index
41from Products.ZCatalog.Catalog import Catalog
42Catalog.updateMetadata = updateMetadata
Note: See TracBrowser for help on using the repository browser.