Ejemplo n.º 1
0
    def Regen(self, tag_service_ids):

        for tag_service_id in tag_service_ids:

            cache_tag_parents_lookup_table_name = GenerateTagParentsLookupCacheTableName(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id)

            self._Execute(
                'DELETE FROM {};'.format(cache_tag_parents_lookup_table_name))

            applicable_service_ids = self.GetApplicableServiceIds(
                tag_service_id)

            tps = ClientTagsHandling.TagParentsStructure()

            for applicable_service_id in applicable_service_ids:

                unideal_statuses_to_pair_ids = self.GetTagParentsIds(
                    service_id=applicable_service_id)

                # we have to collapse the parent ids according to siblings

                ideal_statuses_to_pair_ids = self.IdealiseStatusesToPairIds(
                    tag_service_id, unideal_statuses_to_pair_ids)

                #

                petitioned_fast_lookup = set(
                    ideal_statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED])

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_CURRENT]:

                    if (child_tag_id, parent_tag_id) in petitioned_fast_lookup:

                        continue

                    tps.AddPair(child_tag_id, parent_tag_id)

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_PENDING]:

                    tps.AddPair(child_tag_id, parent_tag_id)

            self._ExecuteMany(
                'INSERT OR IGNORE INTO {} ( child_tag_id, ancestor_tag_id ) VALUES ( ?, ? );'
                .format(cache_tag_parents_lookup_table_name),
                tps.IterateDescendantAncestorPairs())

            if tag_service_id in self._service_ids_to_display_application_status:

                del self._service_ids_to_display_application_status[
                    tag_service_id]
Ejemplo n.º 2
0
    def RegenChains(self, tag_service_ids, tag_ids):

        if len(tag_ids) == 0:

            return

        for tag_service_id in tag_service_ids:

            cache_tag_parents_lookup_table_name = GenerateTagParentsLookupCacheTableName(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id)

            # it is possible that the parents cache currently contains non-ideal tag_ids
            # so, to be safe, we'll also get all sibling chain members

            tag_ids_to_clear_and_regen = set(tag_ids)

            ideal_tag_ids = self.modules_tag_siblings.GetIdeals(
                ClientTags.TAG_DISPLAY_IDEAL, tag_service_id, tag_ids)

            tag_ids_to_clear_and_regen.update(
                self.modules_tag_siblings.GetChainsMembersFromIdeals(
                    ClientTags.TAG_DISPLAY_IDEAL, tag_service_id,
                    ideal_tag_ids))

            # and now all possible current parent chains based on this

            tag_ids_to_clear_and_regen.update(
                self.GetChainsMembers(ClientTags.TAG_DISPLAY_IDEAL,
                                      tag_service_id,
                                      tag_ids_to_clear_and_regen))

            # this should now contain all possible tag_ids that could be in tag parents right now related to what we were given

            self._ExecuteMany(
                'DELETE FROM {} WHERE child_tag_id = ? OR ancestor_tag_id = ?;'
                .format(cache_tag_parents_lookup_table_name),
                ((tag_id, tag_id) for tag_id in tag_ids_to_clear_and_regen))

            # we wipe them

            applicable_tag_service_ids = self.GetApplicableServiceIds(
                tag_service_id)

            tps = ClientTagsHandling.TagParentsStructure()

            for applicable_tag_service_id in applicable_tag_service_ids:

                service_key = self.modules_services.GetService(
                    applicable_tag_service_id).GetServiceKey()

                unideal_statuses_to_pair_ids = self.GetTagParentsIdsChains(
                    applicable_tag_service_id, tag_ids_to_clear_and_regen)

                ideal_statuses_to_pair_ids = self.IdealiseStatusesToPairIds(
                    tag_service_id, unideal_statuses_to_pair_ids)

                #

                petitioned_fast_lookup = set(
                    ideal_statuses_to_pair_ids[HC.CONTENT_STATUS_PETITIONED])

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_CURRENT]:

                    if (child_tag_id, parent_tag_id) in petitioned_fast_lookup:

                        continue

                    tps.AddPair(child_tag_id, parent_tag_id)

                for (child_tag_id,
                     parent_tag_id) in ideal_statuses_to_pair_ids[
                         HC.CONTENT_STATUS_PENDING]:

                    tps.AddPair(child_tag_id, parent_tag_id)

            self._ExecuteMany(
                'INSERT OR IGNORE INTO {} ( child_tag_id, ancestor_tag_id ) VALUES ( ?, ? );'
                .format(cache_tag_parents_lookup_table_name),
                tps.IterateDescendantAncestorPairs())

            if tag_service_id in self._service_ids_to_display_application_status:

                del self._service_ids_to_display_application_status[
                    tag_service_id]