Index UID generation makes sure to not generate the same number

This commit is contained in:
Clément Renault 2019-11-22 11:08:29 +01:00
parent b3b73e2276
commit 0f86ccc035
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -146,10 +146,15 @@ pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
.await .await
.map_err(ResponseError::bad_request)?; .map_err(ResponseError::bad_request)?;
let generated_uid = generate_uid();
let db = &ctx.state().db; 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) { let created_index = match db.create_index(&generated_uid) {
Ok(index) => index, Ok(index) => index,
Err(e) => return Err(ResponseError::create_index(e)), Err(e) => return Err(ResponseError::create_index(e)),