Skip to content

Commit c912ff5

Browse files
fix: generate tile_id in POST /dashboards (#952)
issue: tile_id gets generated by hash of timestamp in microseconds for import dashboard (with multiple tiles) scenarios, more than one tile gets same tile_id fix is to add random string and timestamp to calculate hash for generating tile_id
1 parent 2dbb0a8 commit c912ff5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server/src/handlers/http/users/dashboards.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::{
2525
};
2626
use actix_web::{http::header::ContentType, web, HttpRequest, HttpResponse, Responder};
2727
use bytes::Bytes;
28+
use rand::distributions::DistString;
2829

2930
use chrono::Utc;
3031
use http::StatusCode;
@@ -61,7 +62,14 @@ pub async fn post(req: HttpRequest, body: Bytes) -> Result<impl Responder, Dashb
6162

6263
dashboard.user_id = Some(user_id.clone());
6364
for tile in dashboard.tiles.iter_mut() {
64-
tile.tile_id = Some(get_hash(Utc::now().timestamp_micros().to_string().as_str()));
65+
tile.tile_id = Some(get_hash(
66+
format!(
67+
"{}{}",
68+
rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), 8),
69+
Utc::now().timestamp_micros()
70+
)
71+
.as_str(),
72+
));
6573
}
6674
DASHBOARDS.update(&dashboard);
6775

0 commit comments

Comments
 (0)