Optimize object moves by reindexing only context-aware indexes#161
Optimize object moves by reindexing only context-aware indexes#161mamico wants to merge 9 commits into
Conversation
…d of a full unindex + reindex. The catalog RID is preserved across the move, avoiding stale references and unnecessary work. A new ``moveObject(object, old_path, idxs)`` method is added to ``CatalogTool`` and ``ICatalogTool`` to implement the path remap.
Potential breaking changeBy default this change treats catalog indexes as non-context-aware: on a move, only the indexes contributed by registered Alternatives to reduce the risk
Note on trade-off: in a typical catalog most indexes are context-independent (title, description, subject, ...) and only a few are context-aware. The current approach registers the few context-aware ones (fast by default, but risky if one is missed); the inverted approach registers the many context-independent ones (safe by default, but the speed-up only materializes once they're declared). |
|
What happens to indexes added via ZMI? |
Currently, the new index defaults to a context-unaware behavior. To modify this within the current implementation, a custom utility must be written. Another option is to move the configuration into the index schema, providing the ability to modify it also through the web interface. |
|
Initial benchmark here: https://github.com/mamico/cmfcore-move-benchmark |
Design question: how to declare context-aware indexesThe problemThis optimization treats catalog indexes as non-context-aware by default: on a move, only indexes contributed by registered Any custom index whose value depends on the object's location in the tree but is not registered as a provider will become silently stale after a move. This is a potentially breaking change for sites with custom path-sensitive indexes. AlternativesA — Feature flag (opt-in, safe rollout)
B — Invert the default (opt-out model)
D — Explicit list on
Trade-off summary
Thoughts? |
|
I am mostly neutral here because I don't have any Plone projects, but one thing sticks out:
Adding a CMFCore dependency in ZCatalog sounds like an absolutely terrible idea no matter how I look at it. |
|
What if I add something to the title related to the path, with a subscriber? This solution would not index the title with the new value. It is a corner case but this means I know I've to mark the title as context aware. I would calculate the number of object to move. If the number is more than a critical value, I would ask the user if they want to optimize the move, with a warning about the cases in which this could be problematic. Move a huge amount of object is usually some admins do, not regular users do. A new permission "Move many objects" could be implemented. But this seems complicated and can depend on the instance performances. Move is a special operation, so need a special path:
But this touch the UI, giving the choice to the user. The simplest option is to limit the number of writes. If the result of the indexing is the same (same metadata, same index), don't update the index. I don't see problems in changing the RID but I would investigate why this happen on a reindex. The big problem in the path index is the repeated values. I mean, if I've 10.000 objects under /Plone/afolder, I've an index with tokenization of /Plone/afolder repeated 10.000 times.I would alias the path index to the uuidindex and have a map path:[list of pathuids] stored in the index (or we can add this map to the UUIDIndex). So when moving objects, the list has just to be splitted, getting part of the UUIDs on the new path entry. Move would be fast as removing a list from a list, there are algorithms and data structures that do this in a very optimized way (O(N)). The problem lies in the Zope Folder implementation, where object contained are stored in the folder instead of being stored in a central index, just like filesystems do. This would be the real solution. Folder should ask a central, fast index what are its contents, this would makevery fast the indexing (just a proxy here), moving (fs moving on the same filesystem get microseconds or less) and searching (ls on filesystem is very fast). |
Optimize object moves by reindexing only context-aware indexes instead of a full unindex + reindex. The catalog RID is preserved across the move, avoiding stale references and unnecessary work. A new
moveObject(object, old_path, idxs)method is added toCatalogToolandICatalogToolto implement the path remap.Add
IContextAwareIndexProvider, a named-utility interface that contributes catalog index names which must be reindexed on object moves (path-sensitive, security-sensitive, etc.). Register a named utility providing this interface to extend the default set (path,getId,id,allowedRolesAndUsers). The helperCMFCatalogAware.get_context_aware_indexes()aggregates all registered providers.Based on / inspirated by: