store: add support for modifying and listing labels and caching

Add methods update_labels, clear_labels which update or clear the labels for a
message in the store, and update the cache with the overall counts of labels.

Add a LabelsCache to keep track of the counts and labels_map() to retrieve that
map.
This commit is contained in:
Dirk-Jan C. Binnema
2025-07-27 09:19:48 +03:00
parent 552bb3a7c8
commit 1e628dfcab
4 changed files with 257 additions and 3 deletions

View File

@ -35,6 +35,7 @@
#include <utils/mu-utils.hh>
#include <utils/mu-utils.hh>
#include <utils/mu-option.hh>
#include "mu-labels-cache.hh"
#include <message/mu-message.hh>
@ -338,6 +339,36 @@ public:
*/
static IdVec id_vec(const IdPathVec& ips);
/**
* Update the labels for a message with the labels-delta
*
* Update the message in the store, and update the labels-cache
*
* @param message some message
* @param labels_delta the set of changes
*
* @return the effective changes for this message
*/
Result<Labels::DeltaLabelVec> update_labels(Message& message, const Labels::DeltaLabelVec& labels_delta);
/**
* Clear all labels from message
*
* @param message some message
*
* @retgurn Ok or some error
*/
Result<void> clear_labels(Message& message);
/**
* Get a copy of the map of labels in use.
*
* The map maps label-names to their count
*
* @return map
*/
LabelsCache::Map label_map() const;
/**
* Prototype for the ForEachMessageFunc
*