From 0f86ccc03540d90fc82e87905731a19ec2b5492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 22 Nov 2019 11:08:29 +0100 Subject: [PATCH] Index UID generation makes sure to not generate the same number --- meilidb-http/src/routes/index.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/meilidb-http/src/routes/index.rs b/meilidb-http/src/routes/index.rs index 6f0e5f66c..799e56d53 100644 --- a/meilidb-http/src/routes/index.rs +++ b/meilidb-http/src/routes/index.rs @@ -146,10 +146,15 @@ pub async fn create_index(mut ctx: Context) -> SResult { .await .map_err(ResponseError::bad_request)?; - let generated_uid = generate_uid(); - let db = &ctx.state().db; + let generated_uid = loop { + let uid = generate_uid(); + if db.open_index(&uid).is_none() { + break uid; + } + }; + let created_index = match db.create_index(&generated_uid) { Ok(index) => index, Err(e) => return Err(ResponseError::create_index(e)),