simplify Dupe message and ditch helper function

Calling code doesn't need to know about the existence of such helpers;
it can just rely on code completion to discover the required arguments.
This commit is contained in:
Damien Elmes 2021-01-30 11:10:26 +10:00
parent 5e6dd54c8e
commit 1adc9952f4
4 changed files with 12 additions and 15 deletions

View File

@ -784,13 +784,6 @@ table.review-log {{ {revlog_style} }}
)
def dupe_search_term(mid: int, text: str) -> SearchTerm:
"""Helper function for building a DupeIn message."""
dupe_in = SearchTerm.DupeIn(mid=BackendNoteTypeID(ntid=mid), text=text)
return SearchTerm(dupe=dupe_in)
def nid_search_term(nids: List[int]) -> SearchTerm:
"""Helper function for building a NoteIDs message."""

View File

@ -20,8 +20,8 @@ from bs4 import BeautifulSoup
import aqt
import aqt.sound
from anki.backend_pb2 import SearchTerm
from anki.cards import Card
from anki.collection import dupe_search_term
from anki.hooks import runFilter
from anki.httpclient import HttpClient
from anki.notes import Note
@ -541,7 +541,11 @@ class Editor:
def showDupes(self):
self.mw.browser_search(
dupe_search_term(self.note.model()["id"], self.note.fields[0])
SearchTerm(
dupe=SearchTerm.Dupe(
notetype_id=self.note.model()["id"], first_field=self.note.fields[0]
)
)
)
def fieldsAreBlank(self, previousNote=None):

View File

@ -765,9 +765,9 @@ message BuiltinSearchOrder {
}
message SearchTerm {
message DupeIn {
NoteTypeID mid = 1;
string text = 2;
message Dupe {
int64 notetype_id = 1;
string first_field = 2;
}
enum Flag {
WITHOUT = 0;
@ -803,7 +803,7 @@ message SearchTerm {
string note = 3;
uint32 template = 4;
NoteIDs nids = 5;
DupeIn dupe = 6;
Dupe dupe = 6;
string field_name = 7;
Rated rated = 8;
uint32 added_in_days = 9;

View File

@ -309,8 +309,8 @@ impl From<pb::SearchTerm> for Node<'_> {
}
Filter::Nids(nids) => Node::Search(SearchNode::NoteIDs(nids.into_id_string().into())),
Filter::Dupe(dupe) => Node::Search(SearchNode::Duplicates {
note_type_id: dupe.mid.unwrap_or(pb::NoteTypeId { ntid: 0 }).into(),
text: dupe.text.into(),
note_type_id: dupe.notetype_id.into(),
text: dupe.first_field.into(),
}),
Filter::FieldName(s) => Node::Search(SearchNode::SingleField {
field: escape_anki_wildcards(&s).into_owned().into(),