Skip to content

Commit

Permalink
Combine multiple DB calls into a singular call
Browse files Browse the repository at this point in the history
This is an example demonstration of how we may proceed with Refactor `convert_input.R` to Optimise Workflow PecanProject#3307

Signed-off-by: Abhinav Pandey <[email protected]>
  • Loading branch information
Sweetdevil144 committed Jun 24, 2024
1 parent c027ba2 commit fa99dfc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/data.atmosphere/R/read.register.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fa99dfc

Please sign in to comment.