labels: allow restoring cache-map
E.g. with unexpected termination for mu it is possible that the labels-cache (i.e., the one that is used for auto-completion) gets disconnected from reality. Add a --restore option to `mu label list` to restore the actual labels from the labels seen in the store.
This commit is contained in:
@ -23,6 +23,25 @@
|
||||
|
||||
using namespace Mu;
|
||||
|
||||
Result<void>
|
||||
Mu::LabelsCache::restore(const Store& store)
|
||||
{
|
||||
const auto res{store.run_query("")};
|
||||
if (!res)
|
||||
return Err(Error{Error::Code::Query,
|
||||
"failed to run query: {}",
|
||||
*res.error().what()});
|
||||
label_map_.clear();
|
||||
|
||||
for (auto&& item: *res) {
|
||||
if (auto &&msg{item.message()}; msg) {
|
||||
for (const auto& label: msg->labels())
|
||||
increase(label);
|
||||
}
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr std::string_view path_key = "path:";
|
||||
constexpr std::string_view message_id_key = "message-id:";
|
||||
|
||||
Reference in New Issue
Block a user