Manage monkey patches and performance improvement in Plone 3

Few days ago Jean-Michel François proposed a useful patch for PlonePAS that can be applied for all Plone release until 3.2. Plone 3.3 will embed this patch.

How can we add this patch in a traceable way for an not so old Plone 3.1 or 3.2 ?

First, we can use the new release  of Products.PlonePAS that should be compatible with our Plone installation. The second option is to add a monkey patch in the policy product of our site. One more monkey patch…

Some projects have so many monkey patches that it is difficult to know where is the code that run your site. Martin Aspeli did a tool to handle monkey patches in an elegant way for Zope 2 and Zope 3: collective.monkeypatcher. It allows you to plug  your monkey patches with a simple ZCML directive. Later Gilles Lenfant added a control panel for Zope 2 to be able to have a visual way to follow patches with collective.monkeypatcherpanel.

How does it works?

In your buildout.cfg add :

eggs +=
zcml +=

To create patches add a ‘‘ file in your egg (if you have more than 2 or 3 patches you should create a directory). Our performance patch looks like this:

import copy

def enumerateUsers( self
                  , id=None
                  , login=None
                  , exact_match=False
                  , **kw

    """ See IUserEnumerationPlugin.
    plugin_id = self.getId()

    if id is not None:
    if login is not None:

    if not kw and id:
        data = self._storage.get(id, None)
        if data is None:
            user_info = []
            user_info=[ { 'id' : self.prefix + id,
                     'login' : id,
                     'title' : data.get('fullname', id),
                     'description' : data.get('fullname', id),
                     'email' : data.get('email', ''),
                     'pluginid' : plugin_id } ]
        users=[ (user,data) for (user,data) in self._storage.items()
                    if self.testMemberData(data, criteria, exact_match)]

         user_info=[ { 'id' : self.prefix + user_id,
                     'login' : user_id,
                     'title' : data.get('fullname', user_id),
                     'description' : data.get('fullname', user_id),
                     'email' : data.get('email', ''),
                     'pluginid' : plugin_id } for (user_id, data) in users ]

        return tuple(user_info)

In the configure.zcml of your policy product add an include:

<include file="patches.zcml" />

The file patches.zcml will contain following code:


    <include package="collective.monkeypatcher" file="meta.zcml" />



Run your buildout, start your site and the patch is applied. You can go in the Zope Control Panel to see how many patches are already compatible with this tool.


4 Responses to Manage monkey patches and performance improvement in Plone 3

  1. Just a quick note – there’s only l in my surname. 🙂

  2. encolpe says:

    And it was Jean-Michel François (aka toutpt) not Jean-François Michel.

  3. Martin, you should get the people that produce the GNU spellchecker « aspell » to change their name — I firmly believe it’s the reason for most of the mis-spellings of your name. 😉

  4. My name is correctly spelled. Thanks Encolpe.

%d blogueurs aiment cette page :