Skip to content

Commit

Permalink
fix: generate tile_id in POST /dashboards (#952)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikhilsinhaparseable authored Oct 3, 2024
1 parent 2dbb0a8 commit c912ff5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/src/handlers/http/users/dashboards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
};
use actix_web::{http::header::ContentType, web, HttpRequest, HttpResponse, Responder};
use bytes::Bytes;
use rand::distributions::DistString;

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

dashboard.user_id = Some(user_id.clone());
for tile in dashboard.tiles.iter_mut() {
tile.tile_id = Some(get_hash(Utc::now().timestamp_micros().to_string().as_str()));
tile.tile_id = Some(get_hash(
format!(
"{}{}",
rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), 8),
Utc::now().timestamp_micros()
)
.as_str(),
));
}
DASHBOARDS.update(&dashboard);

Expand Down

0 comments on commit c912ff5

Please sign in to comment.