Spam filter performance and accuracy improvements (part 2)
This commit is contained in:
@@ -7,14 +7,12 @@
|
||||
use common::Server;
|
||||
use email::message::metadata::MessageMetadata;
|
||||
use mail_parser::MessageParser;
|
||||
use spam_filter::{
|
||||
SpamFilterInput, analysis::init::SpamFilterInit, modules::bayes::BayesClassifier,
|
||||
};
|
||||
use spam_filter::{SpamFilterInput, analysis::init::SpamFilterInit};
|
||||
use std::time::Instant;
|
||||
use trc::{SpamEvent, TaskQueueEvent};
|
||||
use types::{collection::Collection, field::EmailField};
|
||||
|
||||
pub trait BayesTrainTask: Sync + Send {
|
||||
pub trait SpamTrainTask: Sync + Send {
|
||||
fn bayes_train(
|
||||
&self,
|
||||
account_id: u32,
|
||||
@@ -23,7 +21,7 @@ pub trait BayesTrainTask: Sync + Send {
|
||||
) -> impl Future<Output = bool> + Send;
|
||||
}
|
||||
|
||||
impl BayesTrainTask for Server {
|
||||
impl SpamTrainTask for Server {
|
||||
async fn bayes_train(&self, account_id: u32, document_id: u32, learn_spam: bool) -> bool {
|
||||
let op_start = Instant::now();
|
||||
// Obtain metadata
|
||||
@@ -68,7 +66,8 @@ impl BayesTrainTask for Server {
|
||||
{
|
||||
Ok(Some(raw_message)) => {
|
||||
// Train bayes classifier for account
|
||||
self.bayes_train_if_balanced(
|
||||
let todo = "fix";
|
||||
/*self.bayes_train_if_balanced(
|
||||
&self.spam_filter_init(SpamFilterInput::from_account_message(
|
||||
&MessageParser::new().parse(&raw_message).unwrap_or_default(),
|
||||
account_id,
|
||||
@@ -76,7 +75,7 @@ impl BayesTrainTask for Server {
|
||||
)),
|
||||
learn_spam,
|
||||
)
|
||||
.await;
|
||||
.await;*/
|
||||
|
||||
trc::event!(
|
||||
Spam(SpamEvent::TrainAccount),
|
||||
|
||||
@@ -139,8 +139,11 @@ impl TaskLock for Task<bool> {
|
||||
}
|
||||
|
||||
fn value_classes(&self) -> impl Iterator<Item = ValueClass> {
|
||||
std::iter::once(ValueClass::TaskQueue(TaskQueueClass::BayesTrain {
|
||||
let todo = "fix";
|
||||
|
||||
std::iter::once(ValueClass::TaskQueue(TaskQueueClass::SpamTrain {
|
||||
due: self.due,
|
||||
blob_hash: Default::default(),
|
||||
learn_spam: self.action,
|
||||
}))
|
||||
}
|
||||
@@ -260,7 +263,7 @@ impl Task<TaskAction> {
|
||||
pub(crate) fn lock_expiry(&self) -> u64 {
|
||||
match &self.action {
|
||||
TaskAction::UpdateIndex(_) => INDEX_EXPIRY,
|
||||
TaskAction::BayesTrain(_) => BAYES_LOCK_EXPIRY,
|
||||
TaskAction::SpamTrain(_) => BAYES_LOCK_EXPIRY,
|
||||
TaskAction::SendAlarm(_) => ALARM_EXPIRY,
|
||||
_ => ALARM_EXPIRY,
|
||||
}
|
||||
@@ -282,7 +285,7 @@ impl Task<TaskAction> {
|
||||
.ok_or_else(|| trc::Error::corrupted_key(key, None, trc::location!()))?,
|
||||
is_insert: *v == 7,
|
||||
}),
|
||||
Some(v @ (1 | 2)) => TaskAction::BayesTrain(*v == 1),
|
||||
Some(v @ (1 | 2)) => TaskAction::SpamTrain(*v == 1),
|
||||
Some(3) => TaskAction::SendAlarm(CalendarAlarm {
|
||||
event_id: key.deserialize_be_u16(U64_LEN + U32_LEN + U32_LEN + 1)?,
|
||||
alarm_id: key.deserialize_be_u16(U64_LEN + U32_LEN + U32_LEN + U16_LEN + 1)?,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use crate::task_manager::bayes::BayesTrainTask;
|
||||
use crate::task_manager::bayes::SpamTrainTask;
|
||||
use crate::task_manager::imip::SendImipTask;
|
||||
use crate::task_manager::index::SearchIndexTask;
|
||||
use crate::task_manager::lock::{TaskLock, TaskLockManager};
|
||||
@@ -56,7 +56,7 @@ pub struct Task<T> {
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||
pub enum TaskAction {
|
||||
UpdateIndex(IndexAction),
|
||||
BayesTrain(bool),
|
||||
SpamTrain(bool),
|
||||
SendAlarm(CalendarAlarm),
|
||||
SendImip,
|
||||
MergeThreads(MergeThreadIds<AHashSet<u32>>),
|
||||
@@ -475,7 +475,7 @@ impl TaskQueueManager for Server {
|
||||
);
|
||||
}
|
||||
}
|
||||
TaskAction::BayesTrain(learn_spam)
|
||||
TaskAction::SpamTrain(learn_spam)
|
||||
if roles.bayes_training.is_enabled_for_hash(&event) =>
|
||||
{
|
||||
if ipc
|
||||
@@ -608,7 +608,7 @@ impl TaskAction {
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
TaskAction::UpdateIndex(_) => "UpdateIndex",
|
||||
TaskAction::BayesTrain(_) => "BayesTrain",
|
||||
TaskAction::SpamTrain(_) => "SpamTrain",
|
||||
TaskAction::SendAlarm(_) => "SendAlarm",
|
||||
TaskAction::SendImip => "SendImip",
|
||||
TaskAction::MergeThreads(_) => "MergeThreads",
|
||||
|
||||
Reference in New Issue
Block a user