From bdc5ce4b6ed72d1c25107ec047b2610312424e0d Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Mon, 24 Nov 2025 15:01:34 +0800 Subject: [PATCH] story: Update Table story to generate increment id. (#1670) Close #1661 --- crates/story/src/table_story.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/story/src/table_story.rs b/crates/story/src/table_story.rs index 18359552..7a3cff19 100644 --- a/crates/story/src/table_story.rs +++ b/crates/story/src/table_story.rs @@ -42,6 +42,7 @@ struct Counter { static ALL_COUNTERS: LazyLock> = LazyLock::new(|| serde_json::from_str(include_str!("./fixtures/counters.json")).unwrap()); +static INCREMENT_ID: LazyLock> = LazyLock::new(|| std::sync::Mutex::new(0)); impl Counter { fn random() -> Self { @@ -124,7 +125,15 @@ impl Stock { } fn random_stocks(size: usize) -> Vec { - (0..size) + // Incremental ID with size. + let start = { + let mut id_lock = INCREMENT_ID.lock().unwrap(); + let start = *id_lock; + *id_lock += size + 1; + start + }; + + (start..start + size) .map(|id| Stock { id, counter: Counter::random(), @@ -268,6 +277,12 @@ impl StockTableDelegate { } fn update_stocks(&mut self, size: usize) { + // Reset incremental ID + { + let mut id_lock = INCREMENT_ID.lock().unwrap(); + *id_lock = 0; + } + self.stocks = random_stocks(size); self.eof = size <= 50; self.loading = false;