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:
Damien Elmes 2021-01-16 19:46:58 +10:00
parent d54acba81f
commit d80a5c56e3
3 changed files with 4 additions and 11 deletions

View File

@ -243,7 +243,7 @@ impl Collection {
let stamp = TimestampMillis::now();
// will rebuild tag list below
let old_tags = self.storage.all_tags_sorted()?;
let old_tags = self.storage.all_tags()?;
self.storage.clear_tags()?;
let total_notes = self.storage.total_notes()?;

View File

@ -16,6 +16,7 @@ fn row_to_tag(row: &Row) -> Result<Tag> {
}
impl SqliteStorage {
/// All tags in the collection, in alphabetical order.
pub(crate) fn all_tags(&self) -> Result<Vec<Tag>> {
self.db
.prepare_cached("select tag, usn, collapsed from tags")?
@ -23,14 +24,6 @@ impl SqliteStorage {
.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
pub(crate) fn get_tag(&self, name: &str) -> Result<Option<Tag>> {
self.db

View File

@ -179,7 +179,7 @@ fn add_child_nodes(tags: &mut Peekable<impl Iterator<Item = Tag>>, parent: &mut
impl Collection {
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);
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
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 new in new_tags.iter() {
if new.name == old.name {