0

In Plone, the ModificationDate and effective date of container objects really returns the last time the container was modified, but doesn't keep track of the contained object's modification times.

I'm wondering if there is a better way, or even some simple built-in way alternative to this awkward and potentially very slow query to determine the date that a container's contents were modified - or in this case below - the last time something was 'added'.

def getFolderModificationDate(folderBrain, catalog):
    """Returns last time content was modified inside a folder"""

    brains = catalog.search(query_request={ "path": folderBrain.getPath(),
                                            "portal_type": 'Article',
                                            'review_state':'published'},
                            sort_index = 'effective',
                            reverse=1,
                            limit=1)

    if brains:
        return brains[0].ModificationDate
    else:
        #return the folder's modificationDate
        return folderBrain.ModificationDate

This date will be used downstream in a non-plone application as a hash value for caching the folder's contents.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
FlipMcF
  • 12,636
  • 2
  • 35
  • 44
  • 1
    Nope, that's how I'd do it. – Martijn Pieters May 30 '13 at 22:35
  • 1
    I agree with Martijn. There's no particular reason why that query would be slow. The catalog is very good at that kind of chore. – SteveM May 31 '13 at 01:23
  • Maybe if only additions, deletions, renames, and reorders constitute a container modification (but not edits/updates of contained objects), you should use respective event subscribers for the container/contained (IObjectAddedEvent, IObjectMovedEvent, IContainerModifiedEvent) to simply set an indexed attribute on the folder? This seems more precise, and might be about the same amount of work? – sdupton May 31 '13 at 15:43
  • @MartijnPieters Answer the question with 'That's how I'd do it' and I'll accept it. #cleanup – FlipMcF Sep 04 '13 at 04:38

1 Answers1

2

Nope, that's exactly how I'd do it.

The alternative would be to use an event to update the modification date of parent folders, but that'd incur a the risk of conflict errors.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343