Database schema optimization - part 11
This commit is contained in:
@@ -284,13 +284,13 @@ impl ValueClass {
|
||||
is_insert,
|
||||
due,
|
||||
} => serializer
|
||||
.write(*due)
|
||||
.write(due.inner())
|
||||
.write(account_id)
|
||||
.write(if *is_insert { 7u8 } else { 8u8 })
|
||||
.write(document_id)
|
||||
.write(index.to_u8()),
|
||||
TaskQueueClass::BayesTrain { due, learn_spam } => serializer
|
||||
.write(*due)
|
||||
.write(due.inner())
|
||||
.write(account_id)
|
||||
.write(if *learn_spam { 1u8 } else { 2u8 })
|
||||
.write(document_id),
|
||||
@@ -300,7 +300,7 @@ impl ValueClass {
|
||||
alarm_id,
|
||||
is_email_alert,
|
||||
} => serializer
|
||||
.write(*due)
|
||||
.write(due.inner())
|
||||
.write(account_id)
|
||||
.write(if *is_email_alert { 3u8 } else { 6u8 })
|
||||
.write(document_id)
|
||||
@@ -309,7 +309,7 @@ impl ValueClass {
|
||||
TaskQueueClass::SendImip { due, is_payload } => {
|
||||
if !*is_payload {
|
||||
serializer
|
||||
.write(*due)
|
||||
.write(due.inner())
|
||||
.write(account_id)
|
||||
.write(4u8)
|
||||
.write(document_id)
|
||||
@@ -319,11 +319,11 @@ impl ValueClass {
|
||||
.write(account_id)
|
||||
.write(5u8)
|
||||
.write(document_id)
|
||||
.write(*due)
|
||||
.write(due.inner())
|
||||
}
|
||||
}
|
||||
TaskQueueClass::MergeThreads { due } => serializer
|
||||
.write(*due)
|
||||
.write(due.inner())
|
||||
.write(account_id)
|
||||
.write(9u8)
|
||||
.write(document_id),
|
||||
|
||||
@@ -223,29 +223,33 @@ pub enum SearchIndexId {
|
||||
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
||||
pub enum TaskQueueClass {
|
||||
UpdateIndex {
|
||||
due: u64,
|
||||
due: TaskEpoch,
|
||||
index: SearchIndex,
|
||||
is_insert: bool,
|
||||
},
|
||||
BayesTrain {
|
||||
due: u64,
|
||||
due: TaskEpoch,
|
||||
learn_spam: bool,
|
||||
},
|
||||
SendAlarm {
|
||||
due: u64,
|
||||
due: TaskEpoch,
|
||||
event_id: u16,
|
||||
alarm_id: u16,
|
||||
is_email_alert: bool,
|
||||
},
|
||||
SendImip {
|
||||
due: u64,
|
||||
due: TaskEpoch,
|
||||
is_payload: bool,
|
||||
},
|
||||
MergeThreads {
|
||||
due: u64,
|
||||
due: TaskEpoch,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)]
|
||||
#[repr(transparent)]
|
||||
pub struct TaskEpoch(pub(crate) u64);
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)]
|
||||
pub enum SearchIndex {
|
||||
Email,
|
||||
@@ -713,3 +717,56 @@ impl AsRef<[Param]> for Params {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskEpoch {
|
||||
/*
|
||||
Structure of the 64-bit epoch:
|
||||
4 bytes: seconds since custom epoch (1632280000)
|
||||
2 bytes: attempt number
|
||||
2 bytes: sequence id
|
||||
*/
|
||||
|
||||
const EPOCH_OFFSET: u64 = 1632280000;
|
||||
|
||||
pub fn now() -> Self {
|
||||
Self::new(now())
|
||||
}
|
||||
|
||||
pub fn new(timestamp: u64) -> Self {
|
||||
Self(timestamp.saturating_sub(Self::EPOCH_OFFSET) << 32)
|
||||
}
|
||||
|
||||
pub fn with_attempt(mut self, attempt: u16) -> Self {
|
||||
self.0 |= (attempt as u64) << 16;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_sequence_id(mut self, sequence_id: u16) -> Self {
|
||||
self.0 |= sequence_id as u64;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_random_sequence_id(self) -> Self {
|
||||
self.with_sequence_id(rand::random())
|
||||
}
|
||||
|
||||
pub fn due(&self) -> u64 {
|
||||
(self.0 >> 32) + Self::EPOCH_OFFSET
|
||||
}
|
||||
|
||||
pub fn attempt(&self) -> u16 {
|
||||
(self.0 >> 16) as u16
|
||||
}
|
||||
|
||||
pub fn sequence_id(&self) -> u16 {
|
||||
self.0 as u16
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn from_inner(inner: u64) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user