Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate update_last_validation_timestamps query #6223

Closed
hansieodendaal opened this issue Mar 19, 2024 · 1 comment
Closed

Evaluate update_last_validation_timestamps query #6223

hansieodendaal opened this issue Mar 19, 2024 · 1 comment
Assignees

Comments

@hansieodendaal
Copy link
Contributor

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)?;
@hansieodendaal hansieodendaal self-assigned this Mar 19, 2024
@hansieodendaal
Copy link
Contributor Author

Fixed in #6232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant