mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
no need for separate all_tags_sorted()
tag is the primary key, so sqlite will give it back to us in sorted order already.
This commit is contained in:
parent
d54acba81f
commit
d80a5c56e3
3 changed files with 4 additions and 11 deletions
|
@ -243,7 +243,7 @@ impl Collection {
|
||||||
let stamp = TimestampMillis::now();
|
let stamp = TimestampMillis::now();
|
||||||
|
|
||||||
// will rebuild tag list below
|
// will rebuild tag list below
|
||||||
let old_tags = self.storage.all_tags_sorted()?;
|
let old_tags = self.storage.all_tags()?;
|
||||||
self.storage.clear_tags()?;
|
self.storage.clear_tags()?;
|
||||||
|
|
||||||
let total_notes = self.storage.total_notes()?;
|
let total_notes = self.storage.total_notes()?;
|
||||||
|
|
|
@ -16,6 +16,7 @@ fn row_to_tag(row: &Row) -> Result<Tag> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SqliteStorage {
|
impl SqliteStorage {
|
||||||
|
/// All tags in the collection, in alphabetical order.
|
||||||
pub(crate) fn all_tags(&self) -> Result<Vec<Tag>> {
|
pub(crate) fn all_tags(&self) -> Result<Vec<Tag>> {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached("select tag, usn, collapsed from tags")?
|
.prepare_cached("select tag, usn, collapsed from tags")?
|
||||||
|
@ -23,14 +24,6 @@ impl SqliteStorage {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all tags in human form, sorted by name
|
|
||||||
pub(crate) fn all_tags_sorted(&self) -> Result<Vec<Tag>> {
|
|
||||||
self.db
|
|
||||||
.prepare_cached("select tag, usn, collapsed from tags order by tag")?
|
|
||||||
.query_and_then(NO_PARAMS, row_to_tag)?
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get tag by human name
|
/// Get tag by human name
|
||||||
pub(crate) fn get_tag(&self, name: &str) -> Result<Option<Tag>> {
|
pub(crate) fn get_tag(&self, name: &str) -> Result<Option<Tag>> {
|
||||||
self.db
|
self.db
|
||||||
|
|
|
@ -179,7 +179,7 @@ fn add_child_nodes(tags: &mut Peekable<impl Iterator<Item = Tag>>, parent: &mut
|
||||||
|
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn tag_tree(&mut self) -> Result<TagTreeNode> {
|
pub fn tag_tree(&mut self) -> Result<TagTreeNode> {
|
||||||
let tags = self.storage.all_tags_sorted()?;
|
let tags = self.storage.all_tags()?;
|
||||||
let tree = tags_to_tree(tags);
|
let tree = tags_to_tree(tags);
|
||||||
|
|
||||||
Ok(tree)
|
Ok(tree)
|
||||||
|
@ -256,7 +256,7 @@ impl Collection {
|
||||||
|
|
||||||
/// Update collapse state of existing tags and register tags in old_tags that are parents of those tags
|
/// Update collapse state of existing tags and register tags in old_tags that are parents of those tags
|
||||||
pub(crate) fn update_tags_collapse(&self, old_tags: Vec<Tag>) -> Result<()> {
|
pub(crate) fn update_tags_collapse(&self, old_tags: Vec<Tag>) -> Result<()> {
|
||||||
let new_tags = self.storage.all_tags_sorted()?;
|
let new_tags = self.storage.all_tags()?;
|
||||||
for old in old_tags.into_iter() {
|
for old in old_tags.into_iter() {
|
||||||
for new in new_tags.iter() {
|
for new in new_tags.iter() {
|
||||||
if new.name == old.name {
|
if new.name == old.name {
|
||||||
|
|
Loading…
Reference in a new issue