Fix broken search index after disabling entrypoint or plugin

This commit is contained in:
Exidex 2024-04-23 21:42:03 +02:00
parent b29dc12832
commit 8249dc55fe
4 changed files with 18 additions and 7 deletions

View file

@ -213,7 +213,12 @@ async function runLoop() {
break;
}
case "ReloadSearchIndex": {
await loadSearchIndex();
try {
await runCommandGenerators();
await loadSearchIndex();
} catch (e) {
console.error("Error occurred when reloading search index", e)
}
break;
}
}
@ -221,7 +226,6 @@ async function runLoop() {
}
await runCommandGenerators();
await loadSearchIndex();
(async () => {

View file

@ -735,6 +735,7 @@ async fn get_command_generator_entrypoint_ids(state: Rc<RefCell<OpState>>) -> an
let result = repository.get_entrypoints_by_plugin_id(&plugin_id.to_string()).await?
.into_iter()
.filter(|entrypoint| entrypoint.enabled)
.filter(|entrypoint| matches!(db_entrypoint_from_str(&entrypoint.entrypoint_type), DbPluginEntrypointType::CommandGenerator))
.map(|entrypoint| entrypoint.id)
.collect::<Vec<_>>();

View file

@ -212,7 +212,9 @@ impl ApplicationManager {
}
pub async fn remove_plugin(&self, plugin_id: PluginId) -> anyhow::Result<()> {
self.db_repository.remove_plugin(&plugin_id.to_string()).await
self.db_repository.remove_plugin(&plugin_id.to_string()).await?;
self.search_index.remove_for_plugin(plugin_id)?;
Ok(())
}
pub fn handle_inline_view(&self, text: &str) {

View file

@ -27,10 +27,10 @@ impl SearchIndex {
schema_builder.add_text_field("entrypoint_type", STORED);
schema_builder.add_text_field("entrypoint_name", TEXT | STORED);
schema_builder.add_text_field("entrypoint_id", STORED);
schema_builder.add_text_field("entrypoint_id", STRING | STORED);
schema_builder.add_text_field("entrypoint_icon_path", STORED);
schema_builder.add_text_field("plugin_name", TEXT | STORED);
schema_builder.add_text_field("plugin_id", STORED);
schema_builder.add_text_field("plugin_id", STRING | STORED);
schema_builder.build()
};
@ -65,7 +65,9 @@ impl SearchIndex {
pub fn remove_for_plugin(&self, plugin_id: PluginId) -> tantivy::Result<()> {
let mut index_writer = self.index.writer(5_000_000)?;
index_writer.delete_term(Term::from_field_text(self.plugin_id, &plugin_id.to_string()));
index_writer.delete_query(Box::new(
TermQuery::new(Term::from_field_text(self.plugin_id, &plugin_id.to_string()), IndexRecordOption::Basic)
))?;
index_writer.commit()?;
Ok(())
@ -79,7 +81,9 @@ impl SearchIndex {
let mut index_writer = self.index.writer(3_000_000)?;
index_writer.delete_term(Term::from_field_text(self.plugin_id, &plugin_id.to_string()));
index_writer.delete_query(Box::new(
TermQuery::new(Term::from_field_text(self.plugin_id, &plugin_id.to_string()), IndexRecordOption::Basic)
))?;
for search_item in search_items {
index_writer.add_document(doc!(