Decouple clearing condition cache from evaluating general messages

This commit is contained in:
Oliver Hamlet
2026-01-02 10:15:39 +00:00
parent 364e2d25c0
commit 46c3ddc884
9 changed files with 121 additions and 41 deletions
+8
View File
@@ -52,6 +52,14 @@ bool Database::Evaluate(const std::string& condition) const {
}
}
void Database::ClearConditionCache() {
try {
return database_->clear_condition_cache();
} catch (const ::rust::Error& e) {
std::rethrow_exception(mapError(e));
}
}
std::vector<std::string> Database::GetKnownBashTags() const {
try {
return convert<std::string>(database_->known_bash_tags());
+2
View File
@@ -26,6 +26,8 @@ public:
bool Evaluate(const std::string& condition) const override;
void ClearConditionCache() override;
std::vector<std::string> GetKnownBashTags() const override;
std::vector<Message> GetGeneralMessages(
+9
View File
@@ -94,6 +94,15 @@ impl Database {
.map_err(Into::into)
}
pub fn clear_condition_cache(&self) -> Result<(), VerboseError> {
self.0
.write()
.map_err(DatabaseLockPoisonError::from)?
.clear_condition_cache();
Ok(())
}
pub fn known_bash_tags(&self) -> Result<Vec<String>, VerboseError> {
Ok(self
.0
+2
View File
@@ -266,6 +266,8 @@ mod ffi {
pub fn evaluate(&self, condition: &str) -> Result<bool>;
pub fn clear_condition_cache(&self) -> Result<()>;
pub fn known_bash_tags(&self) -> Result<Vec<String>>;
pub fn general_messages(&self, evaluate_conditions: bool) -> Result<Vec<Message>>;
@@ -277,6 +277,21 @@ TEST_P(DatabaseInterfaceTest, evaluateShouldReturnFalseIfTheConditionIsFalse) {
EXPECT_FALSE(handle_->GetDatabase().Evaluate("file(\"missing.esp\")"));
}
TEST_P(DatabaseInterfaceTest,
clearConditionCacheShouldCauseConditionsToBeEvaluatedFromScratch) {
const auto condition = "file(\"Blank.esp\")";
EXPECT_TRUE(handle_->GetDatabase().Evaluate(condition));
std::filesystem::remove(dataPath / "Blank.esp");
EXPECT_TRUE(handle_->GetDatabase().Evaluate(condition));
handle_->GetDatabase().ClearConditionCache();
EXPECT_FALSE(handle_->GetDatabase().Evaluate(condition));
}
TEST_P(DatabaseInterfaceTest,
getGroupsShouldReturnAllGroupsListedInTheLoadedMetadata) {
ASSERT_NO_THROW(GenerateMasterlist());