Changeset 1890 for WAeUP_SRP/trunk


Ignore:
Timestamp:
13 Jun 2007, 10:40:51 (19 years ago)
Author:
joachim
Message:

new function removeDeletedDocIds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTool.py

    r1875 r1890  
    2828from OFS.SimpleItem import SimpleItem
    2929
     30from Products.CMFCore.utils import getToolByName
    3031from Products.CPSSchemas.DataStructure import DataStructure
    3132from Products.CPSSchemas.DataModel import DataModel
    … …  
    3536from Products.ZCatalog.ZCatalog import ZCatalog
    3637from Products.CMFCore.permissions import ModifyPortalContent
     38from Products.CMFCore.permissions import ManagePortal
    3739from Products.CMFCore.utils import UniqueObject
    3840from Products.CMFCore.URLTool import URLTool
    … …  
    127129        return pw
    128130    ###)
     131
     132    security.declareProtected(ManagePortal, 'removeDeletedDocIds') ###(
     133    def removeDeletedDocIds(self, max=1000):
     134        """
     135        remove deleted docids from repository commit after max
     136        """
     137        logger = logging.getLogger('WAeUPTool.removeDeletedDocIds')
     138        repository = getToolByName(self, 'portal_repository')
     139        pxtool = getToolByName(self, 'portal_proxies')
     140        pxtool_infos = pxtool.getRevisionsUsed()
     141       
     142        nb_revs = 0
     143        docids_d = {} # all docids
     144        unused_docids_d = {} # all docids that are unused
     145        ids_unused_revs_docids = [] # ids for revs of unused docids
     146        ids_unused_revs = [] # ids for unused revs
     147        total = 0
     148        for id in repository.objectIds():
     149            docid, rev = repository._splitId(id)
     150            if docid is None:
     151                logger.info("invalid doc_id %s" % docid)
     152                continue
     153            nb_revs += 1
     154            docids_d[docid] = None
     155            if not pxtool_infos.has_key(docid):
     156                unused_docids_d[docid] = None
     157                ids_unused_revs_docids.append(id)
     158                ids_unused_revs.append(id)
     159            elif not pxtool_infos[docid].has_key(rev):
     160                ids_unused_revs.append(id)
     161            if len(ids_unused_revs) >= max:
     162                repository.manage_delObjects(ids_unused_revs)
     163                #import pdb;pdb.set_trace()
     164                transaction.commit()
     165                total += max
     166                logger.info('removed %d total %d unused docids ' % (max,total))
     167        anz = len(ids_unused_revs)
     168        if anz > 0:
     169            repository.manage_delObjects(ids_unused_revs)
     170            transaction.commit()
     171            total += anz
     172            logger.info('finished removing %d unused docids ' % (total))
     173           
     174
     175###)
    129176
    130177    security.declareProtected(ModifyPortalContent,'getCredential') ###(
Note: See TracChangeset for help on using the changeset viewer.