diff --git a/pylib/anki/tags.py b/pylib/anki/tags.py index 67ae46c20..7fa0d99ff 100644 --- a/pylib/anki/tags.py +++ b/pylib/anki/tags.py @@ -13,7 +13,7 @@ from __future__ import annotations import pprint import re -from typing import Collection, List, Match, Optional, Sequence, Tuple +from typing import Collection, List, Match, Optional, Sequence import anki # pylint: disable=unused-import import anki._backend.backend_pb2 as _pb @@ -28,19 +28,15 @@ class TagManager: def __init__(self, col: anki.collection.Collection) -> None: self.col = col.weakref() - # all tags + # legacy add-on code expects a List return type def all(self) -> List[str]: - return [t.name for t in self.col._backend.all_tags()] + return list(self.col._backend.all_tags()) def __repr__(self) -> str: d = dict(self.__dict__) del d["col"] return f"{super().__repr__()} {pprint.pformat(d, width=300)}" - # # List of (tag, usn) - def allItems(self) -> List[Tuple[str, int]]: - return [(t.name, t.usn) for t in self.col._backend.all_tags()] - def tree(self) -> TagTreeNode: return self.col._backend.tag_tree() diff --git a/rslib/backend.proto b/rslib/backend.proto index 526488c2b..88d9271e8 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -41,6 +41,10 @@ message Bool { bool val = 1; } +message StringList { + repeated string vals = 1; +} + // IDs used in RPC calls /////////////////////////////////////////////////////////// @@ -212,7 +216,7 @@ service BackendService { // tags rpc ClearUnusedTags(Empty) returns (Empty); - rpc AllTags(Empty) returns (AllTagsOut); + rpc AllTags(Empty) returns (StringList); rpc SetTagCollapsed(SetTagCollapsedIn) returns (Empty); rpc ClearTag(String) returns (Empty); rpc TagTree(Empty) returns (TagTreeNode); @@ -842,21 +846,11 @@ message AddOrUpdateDeckConfigLegacyIn { bool preserve_usn_and_mtime = 2; } -message AllTagsOut { - repeated Tag tags = 1; -} - message SetTagCollapsedIn { string name = 1; bool collapsed = 2; } -message Tag { - string name = 1; - sint32 usn = 2; - bool collapsed = 3; -} - message GetChangedTagsOut { repeated string tags = 1; } diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 2f5894080..924235c05 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -1399,16 +1399,17 @@ impl BackendService for Backend { // tags //------------------------------------------------------------------- - fn all_tags(&self, _input: Empty) -> BackendResult { - let tags: Vec = self.with_col(|col| { - Ok(col - .storage - .all_tags()? - .into_iter() - .map(|t| t.into()) - .collect()) - })?; - Ok(pb::AllTagsOut { tags }) + fn all_tags(&self, _input: Empty) -> BackendResult { + Ok(pb::StringList { + vals: self.with_col(|col| { + Ok(col + .storage + .all_tags()? + .into_iter() + .map(|t| t.name) + .collect()) + })?, + }) } fn set_tag_collapsed(&self, input: pb::SetTagCollapsedIn) -> BackendResult { diff --git a/rslib/src/tags.rs b/rslib/src/tags.rs index 7994af592..1956b4e1e 100644 --- a/rslib/src/tags.rs +++ b/rslib/src/tags.rs @@ -2,7 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use crate::{ - backend_proto::{Tag as TagProto, TagTreeNode}, + backend_proto::TagTreeNode, collection::Collection, err::{AnkiError, Result}, notes::{NoteID, TransformNoteOutput}, @@ -21,26 +21,6 @@ pub struct Tag { pub collapsed: bool, } -impl From for TagProto { - fn from(t: Tag) -> Self { - TagProto { - name: t.name, - usn: t.usn.0, - collapsed: t.collapsed, - } - } -} - -impl From for Tag { - fn from(t: TagProto) -> Self { - Tag { - name: t.name, - usn: Usn(t.usn), - collapsed: t.collapsed, - } - } -} - impl Tag { pub fn new(name: String, usn: Usn) -> Self { Tag {