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

View File

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