Apply suggestions from code review

Co-authored-by: Clément Renault <clement@meilisearch.com>

Apply suggestions from code review

Co-authored-by: Clément Renault <clement@meilisearch.com>
Co-authored-by: Tamo <tamo@meilisearch.com>

Apply suggestions from code review

Co-authored-by: Clément Renault <clement@meilisearch.com>
Co-authored-by: Tamo <tamo@meilisearch.com>

Apply code review suggestion

Co-authored-by: Clément Renault <clement@meilisearch.com>
This commit is contained in:
Loïc Lecrenier 2022-10-19 16:13:14 +02:00 committed by Clément Renault
parent 22cf0559fe
commit 10a547df4f
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 7 additions and 17 deletions

View File

@ -80,21 +80,15 @@ impl IndexScheduler {
})?; })?;
} }
if old_task.enqueued_at != task.enqueued_at { assert!(old_task.enqueued_at != task.enqueued_at, "Cannot update a task's enqueued_at time");
unreachable!("Cannot update a task's enqueued_at time");
}
if old_task.started_at != task.started_at { if old_task.started_at != task.started_at {
if old_task.started_at.is_some() { assert!(old_task.started_at.is_none(), "Cannot update a task's started_at time");
unreachable!("Cannot update a task's started_at time");
}
if let Some(started_at) = task.started_at { if let Some(started_at) = task.started_at {
insert_task_datetime(wtxn, self.started_at, started_at, task.uid)?; insert_task_datetime(wtxn, self.started_at, started_at, task.uid)?;
} }
} }
if old_task.finished_at != task.finished_at { if old_task.finished_at != task.finished_at {
if old_task.finished_at.is_some() { assert!(old_task.finished_at.is_none(), "Cannot update a task's finished_at time");
unreachable!("Cannot update a task's finished_at time");
}
if let Some(finished_at) = task.finished_at { if let Some(finished_at) = task.finished_at {
insert_task_datetime(wtxn, self.finished_at, finished_at, task.uid)?; insert_task_datetime(wtxn, self.finished_at, finished_at, task.uid)?;
} }
@ -187,24 +181,20 @@ impl IndexScheduler {
pub(crate) fn insert_task_datetime( pub(crate) fn insert_task_datetime(
wtxn: &mut RwTxn, wtxn: &mut RwTxn,
database: Database<OwnedType<BEI128>, CboRoaringBitmapCodec>, database: Database<OwnedType<BEI128>, CboRoaringBitmapCodec>,
time: OffsetDateTime, time: OffsetDateTime,
task_id: TaskId, task_id: TaskId,
) -> Result<()> { ) -> Result<()> {
let timestamp = BEI128::new(time.unix_timestamp_nanos()); let timestamp = BEI128::new(time.unix_timestamp_nanos());
let mut task_ids = if let Some(existing) = database.get(&wtxn, &timestamp)? { let mut task_ids = database.get(&wtxn, &timestamp)?.unwrap_or_default();
existing
} else {
RoaringBitmap::new()
};
task_ids.insert(task_id); task_ids.insert(task_id);
database.put(wtxn, &timestamp, &RoaringBitmap::from_iter([task_id]))?; database.put(wtxn, &timestamp, &RoaringBitmap::from_iter([task_id]))?;
Ok(()) Ok(())
} }
pub(crate) fn remove_task_datetime( pub(crate) fn remove_task_datetime(
wtxn: &mut RwTxn, wtxn: &mut RwTxn,
database: Database<OwnedType<BEI128>, CboRoaringBitmapCodec>, database: Database<OwnedType<BEI128>, CboRoaringBitmapCodec>,
time: OffsetDateTime, time: OffsetDateTime,
task_id: TaskId, task_id: TaskId,
) -> Result<()> { ) -> Result<()> {
@ -220,6 +210,7 @@ pub(crate) fn remove_task_datetime(
Ok(()) Ok(())
} }
pub(crate) fn keep_tasks_within_datetimes( pub(crate) fn keep_tasks_within_datetimes(
rtxn: &RoTxn, rtxn: &RoTxn,
tasks: &mut RoaringBitmap, tasks: &mut RoaringBitmap,

View File

@ -211,7 +211,6 @@ pub struct TaskDateQuery {
deserialize_with = "rfc3339_date_or_datetime::deserialize" deserialize_with = "rfc3339_date_or_datetime::deserialize"
)] )]
before_started_at: Option<OffsetDateTime>, before_started_at: Option<OffsetDateTime>,
#[serde( #[serde(
default, default,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",