Database schema optimization - part 3

This commit is contained in:
mdecimus
2025-11-01 19:19:36 +01:00
parent d5c5f12adf
commit 8e1316895b
41 changed files with 1979 additions and 1276 deletions

View File

@@ -20,6 +20,7 @@ use hyper::{Method, header};
use serde_json::json;
use std::future::Future;
use std::sync::Arc;
use store::{search::SearchQuery, write::SearchIndex};
use trc::AddContext;
use utils::url_params::UrlParams;
@@ -399,11 +400,23 @@ impl PrincipalManager for Server {
}
if matches!(typ, Type::Individual | Type::Group) {
// Remove FTS index
if let Err(err) =
server.core.storage.fts.remove_all(principal.id()).await
{
trc::error!(err.details("Failed to delete FTS index"));
// Remove search index
for index in [
SearchIndex::Email,
SearchIndex::Contacts,
SearchIndex::Calendar,
] {
if let Err(err) = server
.core
.storage
.fts
.unindex(
SearchQuery::new(index).with_account_id(principal.id()),
)
.await
{
trc::error!(err.details("Failed to delete FTS index"));
}
}
// Delete bayes model
@@ -516,7 +529,21 @@ impl PrincipalManager for Server {
if matches!(typ, Type::Individual | Type::Group) {
// Remove FTS index
self.core.storage.fts.remove_all(account_id).await?;
for index in [
SearchIndex::Email,
SearchIndex::Contacts,
SearchIndex::Calendar,
] {
if let Err(err) = self
.core
.storage
.fts
.unindex(SearchQuery::new(index).with_account_id(account_id))
.await
{
trc::error!(err.details("Failed to delete FTS index"));
}
}
// Delete bayes model
if self

View File

@@ -23,11 +23,11 @@ use email::{
use http_proto::{request::decode_path_element, *};
use hyper::Method;
use serde_json::json;
use services::task_manager::fts::FtsIndexTask;
use services::task_manager::index::ReindexIndexTask;
use std::future::Future;
use store::{
Serialize, rand,
write::{Archiver, BatchBuilder, ValueClass},
write::{Archiver, BatchBuilder, SearchIndex, ValueClass},
};
use trc::AddContext;
use types::{
@@ -221,7 +221,7 @@ impl ManageStore for Server {
}))
.await
}
(Some("reindex"), id, None, &Method::GET) => {
(Some("reindex"), Some(index), id, &Method::GET) => {
// Validate the access token
access_token.assert_has_permission(Permission::FtsReindex)?;
@@ -237,10 +237,13 @@ impl ManageStore for Server {
None
};
let tenant_id = access_token.tenant.map(|t| t.id);
let index = SearchIndex::try_from_str(index).ok_or_else(|| {
trc::ResourceEvent::BadParameters.reason("Invalid search index specified")
})?;
let jmap = self.clone();
tokio::spawn(async move {
if let Err(err) = jmap.fts_reindex(account_id, tenant_id).await {
if let Err(err) = jmap.reindex(index, account_id, tenant_id).await {
trc::error!(err.details("Failed to reindex FTS"));
}
});