mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-04 03:36:30 +00:00
fix: updated_at was not 'updated' when updating the index name
This commit is contained in:
@ -10,6 +10,7 @@ use meilisearch_types::tasks::{Details, IndexSwap, Kind, KindWithContent, Status
|
||||
use meilisearch_types::versioning::{VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH};
|
||||
use milli::update::Settings as MilliSettings;
|
||||
use roaring::RoaringBitmap;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use super::create_batch::Batch;
|
||||
use crate::processing::{
|
||||
@ -232,8 +233,15 @@ impl IndexScheduler {
|
||||
Batch::IndexUpdate { index_uid, primary_key, new_index_uid, mut task } => {
|
||||
progress.update_progress(UpdateIndexProgress::UpdatingTheIndex);
|
||||
|
||||
// Get the index (renamed or not)
|
||||
let rtxn = self.env.read_txn()?;
|
||||
let index = self.index_mapper.index(&rtxn, &index_uid)?;
|
||||
let mut index_wtxn = index.write_txn()?;
|
||||
|
||||
// Handle rename if new_index_uid is provided
|
||||
let final_index_uid = if let Some(new_uid) = &new_index_uid {
|
||||
index.set_updated_at(&mut index_wtxn, &OffsetDateTime::now_utc())?;
|
||||
|
||||
let mut wtxn = self.env.write_txn()?;
|
||||
|
||||
// Rename the index
|
||||
@ -252,13 +260,9 @@ impl IndexScheduler {
|
||||
} else {
|
||||
index_uid.clone()
|
||||
};
|
||||
// Get the index (renamed or not)
|
||||
let rtxn = self.env.read_txn()?;
|
||||
let index = self.index_mapper.index(&rtxn, &final_index_uid)?;
|
||||
|
||||
// Handle primary key update if provided
|
||||
if let Some(ref primary_key) = primary_key {
|
||||
let mut index_wtxn = index.write_txn()?;
|
||||
let mut builder = MilliSettings::new(
|
||||
&mut index_wtxn,
|
||||
&index,
|
||||
@ -274,9 +278,9 @@ impl IndexScheduler {
|
||||
current_batch.embedder_stats.clone(),
|
||||
)
|
||||
.map_err(|e| Error::from_milli(e, Some(final_index_uid.to_string())))?;
|
||||
index_wtxn.commit()?;
|
||||
}
|
||||
|
||||
index_wtxn.commit()?;
|
||||
// drop rtxn before starting a new wtxn on the same db
|
||||
rtxn.commit()?;
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
use meili_snap::snapshot;
|
||||
|
||||
use time::format_description::well_known::Rfc3339;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
@ -106,3 +108,34 @@ async fn error_update_unexisting_index() {
|
||||
|
||||
assert_eq!(response["error"], expected_response);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn update_index_name() {
|
||||
let server = Server::new_shared();
|
||||
let index = server.unique_index();
|
||||
let (task, code) = index.create(None).await;
|
||||
|
||||
assert_eq!(code, 202);
|
||||
server.wait_task(task.uid()).await.succeeded();
|
||||
|
||||
let new_index = server.unique_index();
|
||||
let (task, _status_code) = index.update_raw(json!({ "uid": new_index.uid })).await;
|
||||
server.wait_task(task.uid()).await.succeeded();
|
||||
|
||||
let (response, code) = new_index.get().await;
|
||||
|
||||
snapshot!(code, @"200 OK");
|
||||
|
||||
assert_eq!(response["uid"], new_index.uid);
|
||||
assert!(response.get("createdAt").is_some());
|
||||
assert!(response.get("updatedAt").is_some());
|
||||
|
||||
let created_at =
|
||||
OffsetDateTime::parse(response["createdAt"].as_str().unwrap(), &Rfc3339).unwrap();
|
||||
let updated_at =
|
||||
OffsetDateTime::parse(response["updatedAt"].as_str().unwrap(), &Rfc3339).unwrap();
|
||||
assert!(created_at < updated_at, "{created_at} should be inferior to {updated_at}");
|
||||
|
||||
snapshot!(response["primaryKey"], @"null");
|
||||
snapshot!(response.as_object().unwrap().len(), @"4");
|
||||
}
|
||||
|
@ -1457,7 +1457,7 @@ impl Index {
|
||||
.0)
|
||||
}
|
||||
|
||||
pub(crate) fn set_updated_at(
|
||||
pub fn set_updated_at(
|
||||
&self,
|
||||
wtxn: &mut RwTxn<'_>,
|
||||
time: &time::OffsetDateTime,
|
||||
|
Reference in New Issue
Block a user