Updating a ZCatalog when objects in it change their path
Squishdot uses ZCatalog quite heavily. When you move/copy/rename a Squishdot site, all the Paths stored in its catalog become incorrect. Not nice... Darrick experienced this when copying a Squishdot site and then trying to delete a load of articles. He didn't notice the uncatalog errors he was getting when he did this and so reported that articles were still showing up in searches after he'd deleted them. That's because the paths stored didn't change when the site was moved and the delete code in squishdot was trying to delete objects with a path at their new location. Rather than rant about the fact that paths are not unique identifiers for objects in a ZODB (because they change when the objects move, and, as this demonstrates, that's not good!) I thought I'd fix the problem. However, the only way I could find to solve it was to add a manage_afterAdd method to Squishdot Sites which recatalogued all postings. This is a _lot_ more resource intensive than it needs to be, since I don't actually want to recatalog all postings (quite expensive when there are 3000+ of them ;-), I just want to modify the paths that ZCatalog has stored. Is there any way to do this? There probably should be ;-) cheers, Chris
Chris Withers wrote:
However, the only way I could find to solve it was to add a manage_afterAdd method to Squishdot Sites which recatalogued all postings. This is a _lot_ more resource intensive than it needs to be, since I don't actually want to recatalog all postings (quite expensive when there are 3000+ of them ;-), I just want to modify the paths that ZCatalog has stored.
Is there any way to do this? There probably should be ;-)
Look in the new ZCatalog product (released for testing a few weeks ago), in the manage_normalize_paths method of ZCatalog.py (line 603). This method goes through every item in the Catalog, and checks to see if its path needs to be changed to the new convention of using the physical path to the object. You could use a modified version of this method to do what you want, calling it from manage_afterAdd. You may need to store the old path to the ZCatalog instance in an attribute, so you'll know how to change the paths. The following code should help, although I haven't tested it. It is shamelessly cribbed from Chris P's manage_normalize_paths method. paths = self._catalog.paths uids = self._catalog.uids for path, rid in uids.items(): new_path=_method_to_return_new_path_after_add(path) del uids[path] paths[rid] = new_path uids[ppath] = rid -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
cheers :-) if people start bitching that it's too slow, I'll give this a go... Chris Steve Alexander wrote:
Chris Withers wrote:
However, the only way I could find to solve it was to add a manage_afterAdd method to Squishdot Sites which recatalogued all postings. This is a _lot_ more resource intensive than it needs to be, since I don't actually want to recatalog all postings (quite expensive when there are 3000+ of them ;-), I just want to modify the paths that ZCatalog has stored.
Is there any way to do this? There probably should be ;-)
Look in the new ZCatalog product (released for testing a few weeks ago), in the manage_normalize_paths method of ZCatalog.py (line 603).
This method goes through every item in the Catalog, and checks to see if its path needs to be changed to the new convention of using the physical path to the object.
You could use a modified version of this method to do what you want, calling it from manage_afterAdd. You may need to store the old path to the ZCatalog instance in an attribute, so you'll know how to change the paths.
The following code should help, although I haven't tested it. It is shamelessly cribbed from Chris P's manage_normalize_paths method.
paths = self._catalog.paths uids = self._catalog.uids
for path, rid in uids.items(): new_path=_method_to_return_new_path_after_add(path) del uids[path] paths[rid] = new_path uids[ppath] = rid
-- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net
participants (2)
-
Chris Withers -
Steve Alexander