def mergeTranslationMessages(self): """Share `TranslationMessage`s between templates where possible.""" order_check = OrderingCheck( key=methodcaller('sharingKey'), reverse=True) for template_number, template in enumerate(self.potemplates): log.info("Merging template %d/%d." % ( template_number + 1, len(self.potemplates))) deletions = 0 order_check.check(template) potmsgset_ids = self._getPOTMsgSetIds(template) for potmsgset_id in potmsgset_ids: potmsgset = POTMsgSet.get(potmsgset_id) tm_ids = self._partitionTranslationMessageIds(potmsgset) before = sum([len(sublist) for sublist in tm_ids], 0) for ids in tm_ids: for id in ids: message = TranslationMessage.get(id) removeSecurityProxy(message).shareIfPossible() self.tm.endTransaction(intermediate=True) after = potmsgset.getAllTranslationMessages().count() deletions += max(0, before - after) report = "Deleted TranslationMessages: %d." % deletions if deletions > 0: log.info(report) else: log.log(DEBUG2, report)
def mergeTranslationMessages(self): """Share `TranslationMessage`s between templates where possible.""" order_check = OrderingCheck(key=methodcaller('sharingKey'), reverse=True) for template_number, template in enumerate(self.potemplates): log.info("Merging template %d/%d." % (template_number + 1, len(self.potemplates))) deletions = 0 order_check.check(template) potmsgset_ids = self._getPOTMsgSetIds(template) for potmsgset_id in potmsgset_ids: potmsgset = POTMsgSet.get(potmsgset_id) tm_ids = self._partitionTranslationMessageIds(potmsgset) before = sum([len(sublist) for sublist in tm_ids], 0) for ids in tm_ids: for id in ids: message = TranslationMessage.get(id) removeSecurityProxy(message).shareIfPossible() self.tm.endTransaction(intermediate=True) after = potmsgset.getAllTranslationMessages().count() deletions += max(0, before - after) report = "Deleted TranslationMessages: %d." % deletions if deletions > 0: log.info(report) else: log.log(DEBUG2, report)
def _removeDuplicateMessages(self): """Get rid of duplicate `TranslationMessages` where needed.""" representatives = {} order_check = OrderingCheck( key=methodcaller('sharingKey'), reverse=True) for template in self.potemplates: order_check.check(template) for potmsgset in template.getPOTMsgSets(False, prefetch=False): key = get_potmsgset_key(potmsgset) if key not in representatives: representatives[key] = potmsgset.id self.tm.endTransaction(intermediate=True) for representative_id in representatives.itervalues(): representative = POTMsgSet.get(representative_id) self._scrubPOTMsgSetTranslations(representative) self.tm.endTransaction(intermediate=True)
def _removeDuplicateMessages(self): """Get rid of duplicate `TranslationMessages` where needed.""" representatives = {} order_check = OrderingCheck(key=methodcaller('sharingKey'), reverse=True) for template in self.potemplates: order_check.check(template) for potmsgset in template.getPOTMsgSets(False, prefetch=False): key = get_potmsgset_key(potmsgset) if key not in representatives: representatives[key] = potmsgset.id self.tm.endTransaction(intermediate=True) for representative_id in representatives.itervalues(): representative = POTMsgSet.get(representative_id) self._scrubPOTMsgSetTranslations(representative) self.tm.endTransaction(intermediate=True)