Ejemplo n.º 1
0
    def RegenerateSearchableSubtagMap(self,
                                      file_service_id,
                                      tag_service_id,
                                      status_hook=None):

        subtags_fts4_table_name = self.GetSubtagsFTS4TableName(
            file_service_id, tag_service_id)
        subtags_searchable_map_table_name = self.GetSubtagsSearchableMapTableName(
            file_service_id, tag_service_id)

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

        query = 'SELECT docid FROM {};'.format(subtags_fts4_table_name)

        BLOCK_SIZE = 10000

        for (group_of_subtag_ids, num_done,
             num_to_do) in HydrusDB.ReadLargeIdQueryInSeparateChunks(
                 self._c, query, BLOCK_SIZE):

            for subtag_id in group_of_subtag_ids:

                result = self._Execute(
                    'SELECT subtag FROM subtags WHERE subtag_id = ?;',
                    (subtag_id, )).fetchone()

                if result is None:

                    continue

                (subtag, ) = result

                searchable_subtag = ClientSearch.ConvertSubtagToSearchable(
                    subtag)

                if searchable_subtag != subtag:

                    searchable_subtag_id = self.modules_tags.GetSubtagId(
                        searchable_subtag)

                    self._Execute(
                        'INSERT OR IGNORE INTO {} ( subtag_id, searchable_subtag_id ) VALUES ( ?, ? );'
                        .format(subtags_searchable_map_table_name),
                        (subtag_id, searchable_subtag_id))

            message = HydrusData.ConvertValueRangeToPrettyString(
                num_done, num_to_do)

            HG.client_controller.frame_splash_status.SetSubtext(message)

            if status_hook is not None:

                status_hook(message)
Ejemplo n.º 2
0
    def AddTags(self, file_service_id, tag_service_id, tag_ids):

        if len(tag_ids) == 0:

            return

        tags_table_name = self.GetTagsTableName(file_service_id,
                                                tag_service_id)

        actually_new_tag_ids = set()

        for tag_id in tag_ids:

            self._Execute(
                'INSERT OR IGNORE INTO {} ( tag_id, namespace_id, subtag_id ) SELECT tag_id, namespace_id, subtag_id FROM tags WHERE tag_id = ?;'
                .format(tags_table_name), (tag_id, ))

            if self._GetRowCount() > 0:

                actually_new_tag_ids.add(tag_id)

        if len(actually_new_tag_ids) > 0:

            if file_service_id == self.modules_services.combined_file_service_id:

                self._Execute(
                    'UPDATE service_info SET info = info + ? WHERE service_id = ? AND info_type = ?;',
                    (len(actually_new_tag_ids), tag_service_id,
                     HC.SERVICE_INFO_NUM_TAGS))

            with self._MakeTemporaryIntegerTable(
                    actually_new_tag_ids, 'tag_id') as temp_tag_ids_table_name:

                # temp tags to fast tag definitions to subtags
                subtag_ids_and_subtags = self._Execute(
                    'SELECT subtag_id, subtag FROM {} CROSS JOIN {} USING ( tag_id ) CROSS JOIN subtags USING ( subtag_id );'
                    .format(temp_tag_ids_table_name,
                            tags_table_name)).fetchall()

                subtags_fts4_table_name = self.GetSubtagsFTS4TableName(
                    file_service_id, tag_service_id)
                subtags_searchable_map_table_name = self.GetSubtagsSearchableMapTableName(
                    file_service_id, tag_service_id)
                integer_subtags_table_name = self.GetIntegerSubtagsTableName(
                    file_service_id, tag_service_id)

                for (subtag_id, subtag) in subtag_ids_and_subtags:

                    searchable_subtag = ClientSearch.ConvertSubtagToSearchable(
                        subtag)

                    if searchable_subtag != subtag:

                        searchable_subtag_id = self.modules_tags.GetSubtagId(
                            searchable_subtag)

                        self._Execute(
                            'INSERT OR IGNORE INTO {} ( subtag_id, searchable_subtag_id ) VALUES ( ?, ? );'
                            .format(subtags_searchable_map_table_name),
                            (subtag_id, searchable_subtag_id))

                    #

                    self._Execute(
                        'INSERT OR IGNORE INTO {} ( docid, subtag ) VALUES ( ?, ? );'
                        .format(subtags_fts4_table_name),
                        (subtag_id, searchable_subtag))

                    if subtag.isdecimal():

                        try:

                            integer_subtag = int(subtag)

                            if CanCacheInteger(integer_subtag):

                                self._Execute(
                                    'INSERT OR IGNORE INTO {} ( subtag_id, integer_subtag ) VALUES ( ?, ? );'
                                    .format(integer_subtags_table_name),
                                    (subtag_id, integer_subtag))

                        except ValueError:

                            pass
Ejemplo n.º 3
0
    def RepopulateMissingSubtags(self, file_service_id, tag_service_id):

        tags_table_name = self.GetTagsTableName(file_service_id,
                                                tag_service_id)
        subtags_fts4_table_name = self.GetSubtagsFTS4TableName(
            file_service_id, tag_service_id)
        subtags_searchable_map_table_name = self.GetSubtagsSearchableMapTableName(
            file_service_id, tag_service_id)
        integer_subtags_table_name = self.GetIntegerSubtagsTableName(
            file_service_id, tag_service_id)

        missing_subtag_ids = self._STS(
            self._Execute(
                'SELECT subtag_id FROM {} EXCEPT SELECT docid FROM {};'.format(
                    tags_table_name, subtags_fts4_table_name)))

        for subtag_id in missing_subtag_ids:

            result = self._Execute(
                'SELECT subtag FROM subtags WHERE subtag_id = ?;',
                (subtag_id, )).fetchone()

            if result is None:

                continue

            (subtag, ) = result

            searchable_subtag = ClientSearch.ConvertSubtagToSearchable(subtag)

            if searchable_subtag != subtag:

                searchable_subtag_id = self.modules_tags.GetSubtagId(
                    searchable_subtag)

                self._Execute(
                    'INSERT OR IGNORE INTO {} ( subtag_id, searchable_subtag_id ) VALUES ( ?, ? );'
                    .format(subtags_searchable_map_table_name),
                    (subtag_id, searchable_subtag_id))

            #

            self._Execute(
                'INSERT OR IGNORE INTO {} ( docid, subtag ) VALUES ( ?, ? );'.
                format(subtags_fts4_table_name),
                (subtag_id, searchable_subtag))

            if subtag.isdecimal():

                try:

                    integer_subtag = int(subtag)

                    if CanCacheInteger(integer_subtag):

                        self._Execute(
                            'INSERT OR IGNORE INTO {} ( subtag_id, integer_subtag ) VALUES ( ?, ? );'
                            .format(integer_subtags_table_name),
                            (subtag_id, integer_subtag))

                except ValueError:

                    pass

        if len(missing_subtag_ids) > 0:

            HydrusData.ShowText(
                'Repopulated {} missing subtags for {}_{}.'.format(
                    HydrusData.ToHumanInt(len(missing_subtag_ids)),
                    file_service_id, tag_service_id))