Skip to content

Commit a9436a8

Browse files
authored
Store (and display) recordings in insertion order (#11415)
1 parent 76ead5d commit a9436a8

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8719,6 +8719,7 @@ dependencies = [
87198719
"anyhow",
87208720
"document-features",
87218721
"emath",
8722+
"indexmap 2.10.0",
87228723
"itertools 0.14.0",
87238724
"nohash-hasher",
87248725
"parking_lot",

crates/store/re_entity_db/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ re_uri.workspace = true
4747
ahash.workspace = true
4848
document-features.workspace = true
4949
emath.workspace = true
50+
indexmap.workspace = true
5051
itertools.workspace = true
5152
nohash-hasher.workspace = true
5253
parking_lot.workspace = true

crates/store/re_entity_db/src/store_bundle.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ pub enum StoreLoadError {
1616
// ---
1717

1818
/// Stores many [`EntityDb`]s of recordings and blueprints.
19+
///
20+
/// The stores are kept and iterated in insertion order to allow the UI to display them by default
21+
/// in opening order.
1922
#[derive(Default)]
2023
pub struct StoreBundle {
21-
recording_store: ahash::HashMap<StoreId, EntityDb>,
24+
// `indexmap` is used to keep track of the insertion order.
25+
recording_store: indexmap::IndexMap<StoreId, EntityDb>,
2226
}
2327

2428
impl StoreBundle {
@@ -38,24 +42,18 @@ impl StoreBundle {
3842
Ok(slf)
3943
}
4044

41-
/// All loaded [`EntityDb`], both recordings and blueprints, in arbitrary order.
45+
/// All loaded [`EntityDb`], both recordings and blueprints, in insertion order.
4246
pub fn entity_dbs(&self) -> impl Iterator<Item = &EntityDb> {
4347
self.recording_store.values()
4448
}
4549

46-
/// All loaded [`EntityDb`], both recordings and blueprints, in arbitrary order.
50+
/// All loaded [`EntityDb`], both recordings and blueprints, in insertion order.
4751
pub fn entity_dbs_mut(&mut self) -> impl Iterator<Item = &mut EntityDb> {
4852
self.recording_store.values_mut()
4953
}
5054

51-
pub fn append(&mut self, mut other: Self) {
52-
for (id, entity_db) in other.recording_store.drain() {
53-
self.recording_store.insert(id, entity_db);
54-
}
55-
}
56-
5755
pub fn remove(&mut self, id: &StoreId) -> Option<EntityDb> {
58-
self.recording_store.remove(id)
56+
self.recording_store.shift_remove(id)
5957
}
6058

6159
// --
@@ -113,29 +111,22 @@ impl StoreBundle {
113111
.insert(entity_db.store_id().clone(), entity_db);
114112
}
115113

116-
/// In no particular order.
114+
/// In insertion order.
117115
pub fn recordings(&self) -> impl Iterator<Item = &EntityDb> {
118116
self.recording_store
119117
.values()
120118
.filter(|log| log.store_kind() == StoreKind::Recording)
121119
}
122120

123-
/// In no particular order.
124-
pub fn blueprints(&self) -> impl Iterator<Item = &EntityDb> {
125-
self.recording_store
126-
.values()
127-
.filter(|log| log.store_kind() == StoreKind::Blueprint)
128-
}
129-
130121
// --
131122

132123
pub fn retain(&mut self, mut f: impl FnMut(&EntityDb) -> bool) {
133124
self.recording_store.retain(|_, db| f(db));
134125
}
135126

136-
/// In no particular order.
127+
/// In insertion order.
137128
pub fn drain_entity_dbs(&mut self) -> impl Iterator<Item = EntityDb> + '_ {
138-
self.recording_store.drain().map(|(_, store)| store)
129+
self.recording_store.drain(..).map(|(_, store)| store)
139130
}
140131

141132
// --

0 commit comments

Comments
 (0)