From a065914e6289d400e6931a77ff2f5f286ed869a9 Mon Sep 17 00:00:00 2001 From: godmodegalactus Date: Thu, 1 Feb 2024 17:55:38 +0100 Subject: [PATCH] Revert "build amt_latest tx array with latest at leftmost position (#51)" This reverts commit a981ff4b2bb53320f51d794c9de4aadeb406c1a4. --- migration.sql | 17 ----------------- src/postgres.rs | 8 +++----- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/migration.sql b/migration.sql index 61a8101..407c8ee 100644 --- a/migration.sql +++ b/migration.sql @@ -166,20 +166,3 @@ BEGIN RETURN tmplist[(len + 1 - n_limit):]; END $$ LANGUAGE plpgsql IMMUTABLE CALLED ON NULL INPUT; - - -DROP FUNCTION array_dedup_append; - --- select banking_stage_results_2.array_prepend_and_truncate('{8,3,2,1}', '{5,3}', 3); -- 5,3,8 -CREATE OR REPLACE FUNCTION banking_stage_results_2.array_prepend_and_truncate(base bigint[], append bigint[], n_limit int) - RETURNS bigint[] -AS $$ -DECLARE - tmplist bigint[]; - len int; -BEGIN - tmplist := append || base; - len := CARDINALITY(tmplist); - RETURN tmplist[:n_limit]; -END -$$ LANGUAGE plpgsql IMMUTABLE CALLED ON NULL INPUT; diff --git a/src/postgres.rs b/src/postgres.rs index bd7a8f9..c76a093 100644 --- a/src/postgres.rs +++ b/src/postgres.rs @@ -32,8 +32,7 @@ use crate::{ }; const BLOCK_WRITE_BUFFER_SIZE: usize = 5; -// note: need to add some a bit more transactions in case of duplicates -const LIMIT_LATEST_TXS_PER_ACCOUNT: i64 = 1000 + 100; +const LIMIT_LATEST_TXS_PER_ACCOUNT: i64 = 100; lazy_static::lazy_static! { static ref ACCOUNTS_SAVING_QUEUE: IntGauge = @@ -442,8 +441,7 @@ impl PostgresSession { &[Type::TEXT, Type::TEXT, Type::BOOL, Type::BOOL, Type::BOOL], ); pin_mut!(writer); - // note: latest transaction must land first in the array - for acc_tx in accounts_for_transaction.iter().rev() { + for acc_tx in accounts_for_transaction { for acc in &acc_tx.accounts { let mut args: Vec<&(dyn ToSql + Sync)> = Vec::with_capacity(4); args.push(&acc.key); @@ -503,7 +501,7 @@ impl PostgresSession { ) SELECT acc_id, - banking_stage_results_2.array_prepend_and_truncate( + array_dedup_append( (SELECT tx_ids FROM banking_stage_results_2.accounts_map_transaction_latest WHERE acc_id=amt_new.acc_id), amt_new.tx_agged, {limit}) AS tx_ids_agg