mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
fix: add missing attachment index cleanup logic
This commit is contained in:
+19
-18
@@ -17,24 +17,20 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
raise_error,
|
account::{
|
||||||
{
|
migration::AccountModel,
|
||||||
account::{
|
state::{DownloadState, DownloadStatus, FolderStatus},
|
||||||
migration::AccountModel,
|
|
||||||
state::{DownloadState, DownloadStatus, FolderStatus},
|
|
||||||
},
|
|
||||||
cache::{
|
|
||||||
imap::{
|
|
||||||
download::flow::{
|
|
||||||
fetch_and_save_by_date, fetch_and_save_full_mailbox, FetchDirection,
|
|
||||||
},
|
|
||||||
mailbox::MailBox,
|
|
||||||
},
|
|
||||||
SEMAPHORE,
|
|
||||||
},
|
|
||||||
error::{code::ErrorCode, BichonResult},
|
|
||||||
store::tantivy::envelope::ENVELOPE_MANAGER,
|
|
||||||
},
|
},
|
||||||
|
cache::{
|
||||||
|
imap::{
|
||||||
|
download::flow::{fetch_and_save_by_date, fetch_and_save_full_mailbox, FetchDirection},
|
||||||
|
mailbox::MailBox,
|
||||||
|
},
|
||||||
|
SEMAPHORE,
|
||||||
|
},
|
||||||
|
error::{code::ErrorCode, BichonResult},
|
||||||
|
raise_error,
|
||||||
|
store::tantivy::{attachment::ATTACHMENT_MANAGER, envelope::ENVELOPE_MANAGER},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
@@ -204,7 +200,9 @@ pub async fn rebuild_mailbox_cache(
|
|||||||
ENVELOPE_MANAGER
|
ENVELOPE_MANAGER
|
||||||
.delete_mailbox_envelopes(account.id, vec![local_mailbox.id])
|
.delete_mailbox_envelopes(account.id, vec![local_mailbox.id])
|
||||||
.await?;
|
.await?;
|
||||||
|
ATTACHMENT_MANAGER
|
||||||
|
.delete_mailbox_attachments(account.id, vec![local_mailbox.id])
|
||||||
|
.await?;
|
||||||
if remote_mailbox.exists == 0 {
|
if remote_mailbox.exists == 0 {
|
||||||
info!(
|
info!(
|
||||||
"Account {}: Mailbox '{}' has no emails on the remote server. The mailbox is empty, no envelopes to fetch.",
|
"Account {}: Mailbox '{}' has no emails on the remote server. The mailbox is empty, no envelopes to fetch.",
|
||||||
@@ -237,6 +235,9 @@ pub async fn rebuild_mailbox_cache_by_date(
|
|||||||
ENVELOPE_MANAGER
|
ENVELOPE_MANAGER
|
||||||
.delete_mailbox_envelopes(account.id, vec![local_mailbox_id])
|
.delete_mailbox_envelopes(account.id, vec![local_mailbox_id])
|
||||||
.await?;
|
.await?;
|
||||||
|
ATTACHMENT_MANAGER
|
||||||
|
.delete_mailbox_attachments(account.id, vec![local_mailbox_id])
|
||||||
|
.await?;
|
||||||
if remote.exists == 0 {
|
if remote.exists == 0 {
|
||||||
info!(
|
info!(
|
||||||
"Account {}: Mailbox '{}' has no emails on the remote server. The mailbox is empty, no envelopes to fetch.",
|
"Account {}: Mailbox '{}' has no emails on the remote server. The mailbox is empty, no envelopes to fetch.",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ use crate::{
|
|||||||
blob::BLOB_MANAGER,
|
blob::BLOB_MANAGER,
|
||||||
envelope::Envelope,
|
envelope::Envelope,
|
||||||
tantivy::{
|
tantivy::{
|
||||||
|
attachment::ATTACHMENT_MANAGER,
|
||||||
fatal_commit,
|
fatal_commit,
|
||||||
fields::{
|
fields::{
|
||||||
F_ACCOUNT_ID, F_DATE, F_FROM, F_ID, F_REGULAR_ATTACHMENT_COUNT, F_SIZE, F_TAGS,
|
F_ACCOUNT_ID, F_DATE, F_FROM, F_ID, F_REGULAR_ATTACHMENT_COUNT, F_SIZE, F_TAGS,
|
||||||
@@ -727,6 +728,10 @@ impl IndexManager {
|
|||||||
.commit()
|
.commit()
|
||||||
.map_err(|e| raise_error!(format!("{:#?}", e), ErrorCode::InternalError))?;
|
.map_err(|e| raise_error!(format!("{:#?}", e), ErrorCode::InternalError))?;
|
||||||
|
|
||||||
|
ATTACHMENT_MANAGER
|
||||||
|
.delete_account_attachments(account_id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if !eml_content_hashes.is_empty() || !attachments_content_hashes.is_empty() {
|
if !eml_content_hashes.is_empty() || !attachments_content_hashes.is_empty() {
|
||||||
self.cleanup_unused_content(eml_content_hashes, attachments_content_hashes)?;
|
self.cleanup_unused_content(eml_content_hashes, attachments_content_hashes)?;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user