'Used internally to implement the Tag Browser'

@api
def get_categories(self, sort=u'name', book_ids=None, already_fixed=None, first_letter_sort=False):

    try:
        with self.safe_read_lock:
            return get_categories(self, sort=sort, book_ids=book_ids, first_letter_sort=first_letter_sort)
    except InvalidLinkTable as err:
        bad_field = err.field_name
        if (bad_field == already_fixed):
            raise
        with self.write_lock:
            self.fields[bad_field].table.fix_link_table(self.backend)
        return self.get_categories(sort=sort, book_ids=book_ids, already_fixed=bad_field)
