Skip to content

Commit d2a4071

Browse files
author
Zoran Cvetkov
committed
add vid to the result struct in order to sort it afterwards
1 parent 472f270 commit d2a4071

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

graph/src/blockchain/block_stream.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ pub struct EntityWithType {
438438
pub entity_op: EntitySubgraphOperation,
439439
pub entity_type: EntityType,
440440
pub entity: Entity,
441+
pub vid: i64,
441442
}
442443

443444
async fn get_entities_for_range(

store/postgres/src/relational.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,12 @@ impl Layout {
550550
let block = ede.block_number;
551551
let entity_type = e.entity_type(&self.input_schema);
552552
let entity = e.deserialize_with_layout::<Entity>(self, None)?;
553+
let vid = ede.vid;
553554
let ewt = EntityWithType {
554555
entity_op,
555556
entity_type,
556557
entity,
558+
vid,
557559
};
558560
Ok((ewt, block))
559561
};
@@ -609,6 +611,12 @@ impl Layout {
609611
}
610612
};
611613
}
614+
615+
// sort the elements in each blocks bucket by vid
616+
for (_, vec) in &mut entities {
617+
vec.sort_by(|a, b| a.vid.cmp(&b.vid));
618+
}
619+
612620
Ok(entities)
613621
}
614622

store/postgres/src/relational_queries.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@ pub struct EntityDataExt {
568568
pub block_number: i32,
569569
#[diesel(sql_type = Text)]
570570
pub id: String,
571+
#[diesel(sql_type = BigInt)]
572+
pub vid: i64,
571573
}
572574

573575
impl Ord for EntityDataExt {
@@ -2068,7 +2070,7 @@ impl<'a> QueryFragment<Pg> for FindRangeQuery<'a> {
20682070
} else {
20692071
self.mut_range.compare_column(&mut out)
20702072
}
2071-
out.push_sql("as block_number, id\n");
2073+
out.push_sql("as block_number, id, vid\n");
20722074
out.push_sql(" from ");
20732075
out.push_sql(table.qualified_name.as_str());
20742076
out.push_sql(" e\n where");

0 commit comments

Comments
 (0)