def checkConsistency(self, stage, progress=None):
        if stage == 'count':
            numItems = self.find(limit=1).count()
            return numItems, 0
        elif stage == 'remove':
            # Check that all items are in existing folders.  Any that are not
            # can be deleted.  Perhaps we should put them in a lost+found
            # instead
            folderIds = self.model('folder').collection.distinct('_id')
            lostItems = self.find({
                '$or': [{'folderId': {'$nin': folderIds}},
                        {'folderId': {'$exists': False}}]})
            numItems = itemsLeft = lostItems.count()
            if numItems:
                if progress is not None:
                    progress.update(message='Removing orphaned items')
                for item in lostItems:
                    setResponseTimeLimit()
                    self.collection.delete_one({'_id': item['_id']})
                    if progress is not None:
                        itemsLeft -= 1
                        progress.update(increment=1, message='Removing '
                                        'orphaned items (%d left)' % itemsLeft)
            return numItems, numItems
        elif stage == 'verify':
            # Check items sizes
            items = self.find()
            numItems = itemsLeft = items.count()
            itemsCorrected = 0
            if progress is not None:
                progress.update(message='Checking items')
            for item in items:
                itemCorrected = False
                setResponseTimeLimit()
                oldSize = item.get('size', 0)
                newSize = self.recalculateSize(item)
                if newSize != oldSize:
                    itemCorrected = True
                newBaseParent = self.parentsToRoot(item, force=True)[0]
                if item['baseParentType'] != newBaseParent['type'] or \
                   item['baseParentId'] != newBaseParent['object']['_id']:
                    self.update(
                        {'_id': item['_id']}, update={'$set': {
                            'baseParentType': newBaseParent['type'],
                            'baseParentId': newBaseParent['object']['_id']
                        }})
                    itemCorrected = True
                if itemCorrected:
                    itemsCorrected += 1
                if progress is not None:
                    itemsLeft -= 1
                    progress.update(increment=1, message='Checking items (%d '
                                    'left)' % itemsLeft)
            return numItems, itemsCorrected
Import all of the modules named in REGISTERED_SCRIPTS
dataset/ETHPy150Open girder/girder/girder/models/item.py/Item.checkConsistency--crossover with--dataset/ETHPy150Open mosesschwartz/scrypture/scrypture/scrypture.py/load_scripts