Skip to content

Commit

Permalink
readit: pre-allocate enough elements
Browse files Browse the repository at this point in the history
  • Loading branch information
vrmiguel committed Jul 25, 2023
1 parent 6a30cd9 commit 6517c29
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ fn readit(
TimestampWithTimeZone,
pgrx::JsonB,
)> = Vec::new();

let _: Result<(), PgmqExtError> = Spi::connect(|mut client| {
let query = read(queue_name, &vt, &limit)?;
let mut tup_table: SpiTupleTable = client.update(&query, None, None)?;
while let Some(row) = tup_table.next() {
let tup_table: SpiTupleTable = client.update(&query, None, None)?;
results.reserve_exact(tup_table.len());

for row in tup_table {
let msg_id = row["msg_id"].value::<i64>()?.expect("no msg_id");
let read_ct = row["read_ct"].value::<i32>()?.expect("no read_ct");
let vt = row["vt"].value::<TimestampWithTimeZone>()?.expect("no vt");
Expand Down

0 comments on commit 6517c29

Please sign in to comment.