From c6e3d554006d4ee95719ad389f128779fadef9f1 Mon Sep 17 00:00:00 2001 From: abdo Date: Sat, 9 Jan 2021 14:15:30 +0300 Subject: [PATCH] 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. --- rslib/src/storage/tag/mod.rs | 12 ++++++++++++ rslib/src/tags.rs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rslib/src/storage/tag/mod.rs b/rslib/src/storage/tag/mod.rs index 51e497835..8d9817856 100644 --- a/rslib/src/storage/tag/mod.rs +++ b/rslib/src/storage/tag/mod.rs @@ -30,6 +30,18 @@ impl SqliteStorage { .collect() } + /// Get all tags in human form, sorted by name + pub(crate) fn all_tags_sorted(&self) -> Result> { + 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 pub(crate) fn get_tag(&self, name: &str) -> Result> { self.db diff --git a/rslib/src/tags.rs b/rslib/src/tags.rs index 8468bc151..7b2621561 100644 --- a/rslib/src/tags.rs +++ b/rslib/src/tags.rs @@ -213,7 +213,7 @@ impl Collection { } pub fn tag_tree(&mut self) -> Result { - let tags = self.all_tags()?; + let tags = self.storage.all_tags_sorted()?; let tree = tags_to_tree(tags); Ok(tree)