def Regen(self, tag_service_ids): for tag_service_id in tag_service_ids: cache_tag_siblings_lookup_table_name = GenerateTagSiblingsLookupCacheTableName( ClientTags.TAG_DISPLAY_IDEAL, tag_service_id) self._Execute( 'DELETE FROM {};'.format(cache_tag_siblings_lookup_table_name)) applicable_service_ids = self.GetApplicableServiceIds( tag_service_id) tss = ClientTagsHandling.TagSiblingsStructure() for applicable_service_id in applicable_service_ids: statuses_to_pair_ids = self.GetTagSiblingsIds( service_id=applicable_service_id) petitioned_fast_lookup = set( statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED]) for (bad_tag_id, good_tag_id ) in statuses_to_pair_ids[HC.CONTENT_STATUS_CURRENT]: if (bad_tag_id, good_tag_id) in petitioned_fast_lookup: continue tss.AddPair(bad_tag_id, good_tag_id) for (bad_tag_id, good_tag_id ) in statuses_to_pair_ids[HC.CONTENT_STATUS_PENDING]: tss.AddPair(bad_tag_id, good_tag_id) self._ExecuteMany( 'INSERT OR IGNORE INTO {} ( bad_tag_id, ideal_tag_id ) VALUES ( ?, ? );' .format(cache_tag_siblings_lookup_table_name), tss.GetBadTagsToIdealTags().items()) if tag_service_id in self._service_ids_to_display_application_status: del self._service_ids_to_display_application_status[ tag_service_id]
def RegenChains(self, tag_service_ids, tag_ids): # as this guy can change ideals, the related parent chains need to be regenned afterwards too if len(tag_ids) == 0: return for tag_service_id in tag_service_ids: cache_tag_siblings_lookup_table_name = GenerateTagSiblingsLookupCacheTableName( ClientTags.TAG_DISPLAY_IDEAL, tag_service_id) tag_ids_to_clear_and_regen = set(tag_ids) ideal_tag_ids = self.GetIdeals(ClientTags.TAG_DISPLAY_IDEAL, tag_service_id, tag_ids) tag_ids_to_clear_and_regen.update( self.GetChainsMembersFromIdeals(ClientTags.TAG_DISPLAY_IDEAL, tag_service_id, ideal_tag_ids)) self._ExecuteMany( 'DELETE FROM {} WHERE bad_tag_id = ? OR ideal_tag_id = ?;'. format(cache_tag_siblings_lookup_table_name), ((tag_id, tag_id) for tag_id in tag_ids_to_clear_and_regen)) applicable_tag_service_ids = self.GetApplicableServiceIds( tag_service_id) tss = ClientTagsHandling.TagSiblingsStructure() for applicable_tag_service_id in applicable_tag_service_ids: service_key = self.modules_services.GetService( applicable_tag_service_id).GetServiceKey() statuses_to_pair_ids = self.GetTagSiblingsIdsChains( applicable_tag_service_id, tag_ids_to_clear_and_regen) petitioned_fast_lookup = set( statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED]) for (bad_tag_id, good_tag_id ) in statuses_to_pair_ids[HC.CONTENT_STATUS_CURRENT]: if (bad_tag_id, good_tag_id) in petitioned_fast_lookup: continue tss.AddPair(bad_tag_id, good_tag_id) for (bad_tag_id, good_tag_id ) in statuses_to_pair_ids[HC.CONTENT_STATUS_PENDING]: tss.AddPair(bad_tag_id, good_tag_id) self._ExecuteMany( 'INSERT OR IGNORE INTO {} ( bad_tag_id, ideal_tag_id ) VALUES ( ?, ? );' .format(cache_tag_siblings_lookup_table_name), tss.GetBadTagsToIdealTags().items()) if tag_service_id in self._service_ids_to_display_application_status: del self._service_ids_to_display_application_status[ tag_service_id]