Skip to content

Commit

Permalink
Merge 'dont-update-metadata' fix from 2.6 branch. When the caller spe…
Browse files Browse the repository at this point in the history
…cifies that only a particular set of indexes should be updated, don't update the object metadata unconditionally.
  • Loading branch information
mcdonc committed Oct 5, 2003
1 parent bef5b58 commit 82c23fb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 43 deletions.
66 changes: 40 additions & 26 deletions Catalog.py
Expand Up @@ -287,35 +287,14 @@ def getIndex(self, name):
""" get an index wrapped in the catalog """
return self.indexes[name].__of__(self)

# the cataloging API

def catalogObject(self, object, uid, threshold=None,idxs=[]):
"""
Adds an object to the Catalog by iteratively applying it
all indexes.
'object' is the object to be cataloged
'uid' is the unique Catalog identifier for this object
"""

def updateMetadata(self, object, uid):
""" Given an object and a uid, update the column data for the
uid with the object data iff the object has changed """
data = self.data

# meta_data is stored as a tuple for efficiency
index = self.uids.get(uid, None)
newDataRecord = self.recordify(object)

index=self.uids.get(uid, None)
if index is not None:
# old data

if data.get(index, 0) != newDataRecord:
# Update the meta-data, if necessary
data[index] = newDataRecord

else:
# new data

if index is None:
if type(data) is IOBTree:
# New style, get random id

Expand All @@ -340,14 +319,49 @@ def catalogObject(self, object, uid, threshold=None,idxs=[]):
index = data.keys()[-1] + 1
else:
index=0
# meta_data is stored as a tuple for efficiency
data[index] = newDataRecord
else:
if data.get(index, 0) != newDataRecord:
data[index] = newDataRecord
return index

# the cataloging API

def catalogObject(self, object, uid, threshold=None,idxs=None):
"""
Adds an object to the Catalog by iteratively applying it
all indexes.
'object' is the object to be cataloged
'uid' is the unique Catalog identifier for this object
"""

if idxs is None:
idxs = []

data = self.data
index = self.uids.get(uid, None)

if index is None: # we are inserting new data
index = self.updateMetadata(object, uid)

try: self.__len__.change(1)
except AttributeError: pass # No managed length (old-style)

self.uids[uid] = index
self.paths[index] = uid

else: # we are updating old data
if not idxs:
# if the caller specifies that we should update only a
# specific set of indexes, we don't do a metadata update.
self.updateMetadata(object, uid)

# do indexing

total = 0

if idxs==[]: use_indexes = self.indexes.keys()
Expand Down
47 changes: 30 additions & 17 deletions tests/testCatalog.py
Expand Up @@ -174,6 +174,23 @@ def testSearch(self):
sr = self._catalog.search(query)
self.assertEqual(len(sr), 3)


class dummy(ExtensionClass.Base):
att1 = 'att1'
att2 = 'att2'
att3 = ['att3']
def __init__(self, num):
self.num = num

def col1(self):
return 'col1'

def col2(self):
return 'col2'

def col3(self):
return ['col3']

class TestCatalogObject(unittest.TestCase):

upper = 1000
Expand Down Expand Up @@ -215,23 +232,6 @@ def setUp(self):
self._catalog.addColumn('att3')
self._catalog.addColumn('num')

class dummy(ExtensionClass.Base):
att1 = 'att1'
att2 = 'att2'
att3 = ['att3']
def __init__(self, num):
self.num = num

def col1(self):
return 'col1'

def col2(self):
return 'col2'

def col3(self):
return ['col3']


for x in range(0, self.upper):
self._catalog.catalogObject(dummy(self.nums[x]), `x`)
self._catalog.aq_parent = dummy('foo') # fake out acquisition
Expand Down Expand Up @@ -404,6 +404,19 @@ def testBigSortLimit(self):
self.assertEqual(a.actual_result_count, self.upper)
self.assertEqual(a[0].num, self.upper - 1)

def testUpdateIndexLeavesMetadataAlone(self):
ob = dummy(9999)
self._catalog.catalogObject(ob, `9999`)
brain = self._catalog(num=9999)[0]
self.assertEqual(brain.att1, 'att1')
ob.att1 = 'foobar'
self._catalog.catalogObject(ob, `9999`, idxs=['num'])
brain = self._catalog(num=9999)[0]
self.assertEqual(brain.att1, 'att1')
self._catalog.catalogObject(ob, `9999`)
brain = self._catalog(num=9999)[0]
self.assertEqual(brain.att1, 'foobar')


class objRS(ExtensionClass.Base):

Expand Down

0 comments on commit 82c23fb

Please sign in to comment.