fill_missing_tags's input should be sorted

I assumed that fill_missing_tags will work correctly with un unsorted
tag list previously so I replaced the all_tags_sorted call, but take the following the list for example:

["foo::bar", "foo"]

This will cause "foo" to be counted like a missing tag, since it's
encountered the first time when looking at "foo::bar"", and its config
and other associated data will be lost.
This commit is contained in:
abdo 2021-01-09 14:15:30 +03:00
parent b33267f754
commit c6e3d55400
2 changed files with 13 additions and 1 deletions

View file

@ -30,6 +30,18 @@ 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 id, name, usn, config from tags order by name")?
.query_and_then(NO_PARAMS, |row| {
let mut tag = row_to_tag(row)?;
tag.name = native_tag_name_to_human(&tag.name);
Ok(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

View file

@ -213,7 +213,7 @@ impl Collection {
} }
pub fn tag_tree(&mut self) -> Result<TagTreeNode> { pub fn tag_tree(&mut self) -> Result<TagTreeNode> {
let tags = self.all_tags()?; let tags = self.storage.all_tags_sorted()?;
let tree = tags_to_tree(tags); let tree = tags_to_tree(tags);
Ok(tree) Ok(tree)