store/server: centralize docids-for-msgid

No need for two near-identical impls

Remove some dead declarations.
This commit is contained in:
Dirk-Jan C. Binnema
2023-07-09 23:20:32 +03:00
parent 0b4f7c4cbe
commit 18490a818d
4 changed files with 45 additions and 57 deletions

View File

@ -423,8 +423,6 @@ Store::Private::move_message_unlocked(Message&& msg,
return Ok(std::move(msg));
}
/* get a vec of all messages with the given message id */
static Store::IdMessageVec
messages_with_msgid(const Store& store, const std::string& msgid, size_t max=100)
@ -460,6 +458,36 @@ messages_with_msgid(const Store& store, const std::string& msgid, size_t max=100
}
static Result<std::string>
message_id_query(const std::string& msgid)
{
if (msgid.empty())
return Err(Error::Code::InvalidArgument, "empty message-id");
else if (msgid.size() > MaxTermLength)
return Err(Error::Code::InvalidArgument, "message-id too long");
else
return Ok(mu_format("{}:{}", field_from_id(Field::Id::MessageId).shortcut, msgid));
}
Result<Store::IdVec>
Store::find_docids_with_message_id(const std::string& msgid) const
{
std::lock_guard guard{priv_->lock_};
if (auto&& query{message_id_query(msgid)}; !query)
return Err(std::move(query.error()));
else if (auto&& res{run_query(*query)}; !res)
return Err(std::move(res.error()));
else {
Store::IdVec ids;
for (auto&& mi: *res)
ids.emplace_back(mi.doc_id());
return Ok(std::move(ids));
}
}
static Flags
filter_dup_flags(Flags old_flags, Flags new_flags)
{