Package: collective.metadataversion
A simple helper for conditional metadata updatesThe portal catalog of Zope / Plone sites holds socalled “brains” which have
metadata attributes  containing the data to be used when the catalog is
searched and the search results are listed.Those metadata columns – like index values – can be customized,
and they can evolve over time, as your customization package(s) evolve(s).
If your database is small, you’ll happily reindex the whole data
whenenver you change something to your metadata (or indexes).
Or if your metadata is really cheap.But perhaps this is not the case.Perhaps you like to be able to reindex the most important parts first,
and the rest can simply become reindexed when changed.
And then decide there are more objects which really should be reindexed
without being changed themselves.Perhaps you’d even like to be able to handle cases where objects
with different generations of metadata setups occur.This simple little package doesn’t do anything peculiarly magic;
it just provides a littlemetadata_versioncolumn which holds
the current tip number of your own metadata evolution,
and it offers a little utility which helps you to reindex only those objects
which don’t feature the most current metadata setup yet.Featuresprovides a simplemetadata_versionmetadata attribute, anda simple utility to reindex objects only if theirmetadata_versionis
outdatedExamplesThis is how the.utils.make_metadata_updaterutility function is used.In your policy package’s setuphandler module, you may have:from collective.metadataversion.decorator import step
from collective.metadataversion.utils import make_metadata_updater

...
@step
def update_metadata_of_prominent_objects(context, logger):
    reindex = make_metadata_updater(context, logger, 42)
    catalog = getToolByName(context, 'portal_catalog')
    updated, skipped = 0, 0
    for brain in catalog(<my fancy query>):
        if reindex(brain):
            updated += 1
        else:
            skipped += 1
    (... logging ad libitum ...)

@step
def update_metadata_of_remaining_objects(context, logger):
    reindex = make_metadata_updater(context, logger, 42)
    catalog = getToolByName(context, 'portal_catalog')
    updated, skipped = 0, 0
    for brain in catalog({}):
        if reindex(brain):
            updated += 1
        else:
            skipped += 1
    (... logging ad libitum ...)Thereindexfunction returned by make_metadata_updater() will reindex every
object (given by brain) which has not been recently reindexed (with
metadata_version=42), and by default refresh a “cheap” selection of indexes.Starting with the 2nd call to the first upgrade step, nothing will be actually
reindexed anymore (unless your <fancy query> spans some more objects now), since
everything is up-to-date;
the 2nd upgrade step will update all remaining objects (which might not need to
be updated so urgently), and skip all objects caught by the <fancy query>.NotesThe@stepdecorator makes sure you have a non-None logger.The factory functionmake_metadata_updatertakes care for updating the
registry value, provided the givenmetadata_versionvalue is greater than
the old one (or forced).This is currently the only utility we provide for this purpose.
However, you can adjust the registry key directly yourself, if you prefer.There are a few keyword-only options for customization.TranslationsThis product has been translated intoEnglishGermanInstallationInstall collective.metadataversion by adding it to your buildout:[buildout]
...
eggs =
    collective.metadataversionand then runningbin/buildout.After your Zope instance was restarted, you’ll have thecollective.metadataversionpackage in your extensions view
(/prefs_install_products_form), or in the “Quick installer”;
select and activate it.After activation, you’ll have a (prefixed)metadata_versionkey in your
configuration registry which you can adjust according to your needs.ContributeIssue Tracker:https://github.com/collective/metadataversion/issuesSource Code:https://github.com/collective/metadataversionSupportIf you are having issues, please let us know;
please use theissue trackermentioned above.LicenseThe project is licensed under the GPLv2.ContributorsTobias Herp,tobias.herp@visaplan.comChangelog0.2.1 (2022-03-04)New Features:New function .utils.extract_mmu_kwargsImprovements:Improved the docstring of .utils.make_metadata_updater[tobiasherp]0.2.0 (2021-11-17)Bugfixes:Register themetadata_versionindexer,
andattach it to IContentishNew Features:New settingdefault_idxsto adjust the (cheap!) indexes
to be refreshed for “metadata-only” updates[tobiasherp]0.1.0 (2021-09-21)Initial release.
[tobiasherp]