Skip to content

Commit

Permalink
[db] Fix order of keys in select by keys #1234 (#1235)
Browse files Browse the repository at this point in the history
Update db.rs
  • Loading branch information
michaelvlach authored Sep 4, 2024
1 parent 1a7916a commit 455c46c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions agdb/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,17 @@ impl<Store: StorageData> DbImpl<Store> {
db_id: DbId,
keys: &[DbValue],
) -> Result<Vec<DbKeyValue>, DbError> {
Ok(self
let mut sortable_values: Vec<(usize, DbKeyValue)> = self
.values
.iter_key(&self.storage, &db_id)
.filter(|kv| keys.contains(&kv.1.key))
.map(|kv| kv.1)
.collect())
.filter_map(|kv| {
keys.iter()
.position(|k| *k == kv.1.key)
.map(|pos| (pos, kv.1))
})
.collect();
sortable_values.sort_by_key(|(i, _)| *i);
Ok(sortable_values.into_iter().map(|(_, kv)| kv).collect())
}

fn graph_index(&self, id: i64) -> Result<GraphIndex, QueryError> {
Expand Down

0 comments on commit 455c46c

Please sign in to comment.