tari-project/tari

Evaluate `update_last_validation_timestamps` query

Closed this issue · 1 comments

Evaluate diesel vs. raw

    fn update_last_validation_timestamps(&self, hashes: Vec<FixedHash>) -> Result<(), OutputManagerStorageError> {
        let start = Instant::now();
        let mut conn = self.database_connection.get_pooled_connection()?;
        let acquire_lock = start.elapsed();

        // diesel::update(outputs::table.filter(outputs::hash.eq_any(hashes.iter().map(|hash| hash.to_vec()))))
        //     .set(outputs::last_validation_timestamp.eq(Some(Utc::now().naive_utc())))
        //     .execute(&mut conn)
        //     .num_rows_affected_or_not_found(hashes.len())?;

        // TODO: This raw query is being evaluated, as the diesel query above is not as performant as expected.
        let sql_query = format!(
            r#"
            UPDATE outputs
            SET last_validation_timestamp = '{}'
            WHERE hash IN ({})
            "#,
            Utc::now().naive_utc(),
            hashes
                .iter()
                .map(|hash| format!("'{}'", hash.to_string()))
                .collect::<Vec<_>>()
                .join(",")
        );
        conn.batch_execute(&sql_query)?;