From fa99dfcf8f5415c6e4d54311482af2881cc06317 Mon Sep 17 00:00:00 2001 From: Abhinav Pandey Date: Mon, 24 Jun 2024 08:17:56 +0530 Subject: [PATCH] Combine multiple DB calls into a singular call This is an example demonstration of how we may proceed with Refactor `convert_input.R` to Optimise Workflow #3307 Signed-off-by: Abhinav Pandey --- modules/data.atmosphere/R/read.register.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/data.atmosphere/R/read.register.R b/modules/data.atmosphere/R/read.register.R index b7a7db708a0..4e809e84dd6 100644 --- a/modules/data.atmosphere/R/read.register.R +++ b/modules/data.atmosphere/R/read.register.R @@ -35,10 +35,14 @@ read.register <- function(register.xml, con) { } else if ((!is.null(register$format$id) & is.null(register$format$name)) | (!is.null(register$format$id) & is.null(register$format$mimetype))) { - register$format$name <- PEcAn.DB::db.query( - paste("SELECT name from formats where id = ", register$format$id), con)[[1]] - register$format$mimetype <- PEcAn.DB::db.query( - paste("SELECT mime_type from formats where id = ", register$format$id), con)[[1]] + # get name and mime_type from formats table in a singular dataframe + format.info <- PEcAn.DB::db.query( + paste("SELECT name, mime_type FROM formats WHERE id = ", register$format$id), con + ) + + # Assign the values from the data frame to the respective columns in register$format + register$format$name <- format.info$name + register$format$mimetype <- format.info$mime_type } else if (is.null(register$format$id) & !is.null(register$format$name) & !is.null(register$format$mimetype)) { register$format$id <- PEcAn.DB::db.query( paste0("SELECT id from formats where name = '", register$format$name,