From a8fc66f73e692d9c3eda11ab0ff3fd9034bb8ac9 Mon Sep 17 00:00:00 2001 From: EthanFreestone <54310740+EthanFreestone@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:13:03 +0000 Subject: [PATCH] ERM-3455: pushPkg endpoint in mod-agreements works unexpectedly slowly (#839) * perf: pushPkg endpoint in mod-agreements works unexpectedly slowly Impropve transaction handling in a couple of key areas to facilitate pushPkg functionality -- matches changes made in ingest process and for pushPCI previously ERM-3455 * fix: Remove special Org transaction handling as it causes int tests to crash (Perf seems to be fine enough without it) * fix: Reinstated flushes in coordinateOrg, turns out they were necessary --- .../olf/DependentModuleProxyService.groovy | 9 +++--- .../olf/general/pushKB/PushKBService.groovy | 32 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/service/grails-app/services/org/olf/DependentModuleProxyService.groovy b/service/grails-app/services/org/olf/DependentModuleProxyService.groovy index dab86d77..04e233c9 100644 --- a/service/grails-app/services/org/olf/DependentModuleProxyService.groovy +++ b/service/grails-app/services/org/olf/DependentModuleProxyService.groovy @@ -21,11 +21,10 @@ public class DependentModuleProxyService { OkapiClient okapiClient public Org coordinateOrg(String orgName) { - // Simply call the verb method on the client (get, post, put, delete). The client itself should take care of everything else. // Get and Delete take the uri with optional params map for the query string. // Post, Put and Patch take in the uri, data that can be converted to json (String or map) and optional params map for the query string. - Org org = Org.findByName(orgName) + Org org = Org.findByName(orgName) // This cannot be swapped for executeQuery SELECT -- possibly due to the bindUsingWhenRef if (!org) { log.debug "No local org for ${orgName}. Check vendors." @@ -51,7 +50,7 @@ public class DependentModuleProxyService { "first" : 0, "last" : 0 } - */ + */ switch (mod_vendor_lookup_result.total_records) { case 1: @@ -62,7 +61,7 @@ public class DependentModuleProxyService { name: result.name, orgsUuid: result.id, sourceURI: "/vendor/${result.id}" - ).save( flush:true, failOnError:true ) + ).save( flush: true, failOnError:true ) break case 0: @@ -74,7 +73,7 @@ public class DependentModuleProxyService { // Create a new local one. log.debug "No vendor found. Adding local org for ${orgName}" - org = (new Org(name:orgName)).save(flush:true, failOnError:true) + org = (new Org(name:orgName)).save( flush: true, failOnError:true ) break default: diff --git a/service/grails-app/services/org/olf/general/pushKB/PushKBService.groovy b/service/grails-app/services/org/olf/general/pushKB/PushKBService.groovy index 15070769..072199e0 100644 --- a/service/grails-app/services/org/olf/general/pushKB/PushKBService.groovy +++ b/service/grails-app/services/org/olf/general/pushKB/PushKBService.groovy @@ -71,20 +71,26 @@ class PushKBService implements DataBinder { if (utilityService.checkValidBinding(package_data)) { // Start a transaction -- method in packageIngestService needs this - Pkg.withNewTransaction { status -> - // Farm out package lookup and creation to a separate method - - // These calls mirror what's in upsertPackage but conveniently avoid the - // logic which handles TIPPS - Pkg pkg = packageIngestService.lookupOrCreatePkg(package_data); - // Retain logging information - MDC.put('packageSource', pkg.source.toString()) - MDC.put('packageReference', pkg.reference.toString()) - - // Update identifiers from citation - identifierService.updatePackageIdentifiers(pkg, package_data.identifiers) + Pkg.withSession { currentSess -> + Pkg.withTransaction { + Pkg.withNewSession { newSess -> + Pkg.withTransaction { + // Farm out package lookup and creation to a separate method + + // These calls mirror what's in upsertPackage but conveniently avoid the + // logic which handles TIPPS + Pkg pkg = packageIngestService.lookupOrCreatePkg(package_data); + // Retain logging information + MDC.put('packageSource', pkg.source.toString()) + MDC.put('packageReference', pkg.reference.toString()) + + // Update identifiers from citation + identifierService.updatePackageIdentifiers(pkg, package_data.identifiers) + } + newSess.clear() + } + } } - } } result.success = true