libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit dcc695adec0588bdd1f32f42bbce18abd3214a0b
parent a95566847aa885bacd60393cc1ac199329e8c304
Author: Antoine A <>
Date:   Mon, 30 Sep 2024 11:56:47 +0200

nexus: more efficient fetch

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/cli/EbicsFetch.kt | 39+++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/cli/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/cli/EbicsFetch.kt @@ -339,6 +339,29 @@ class EbicsFetch: CliktCommand() { ) val docs = if (documents.isEmpty()) OrderDoc.entries else documents.toList() val requestedOrders = docs.map { cfg.dialect.downloadDoc(it, false) }.toSet() + + /** Fetch requested documents only if they have new content */ + suspend fun fetchAvailableDocuments(pinnedStartArg: Instant?): Boolean { + val orders = if (requestedOrders.size > 1) { + // Always add HAC as it is never announced + val pendingOrders = mutableSetOf<EbicsOrder>(EbicsOrder.V3.HAC) + client.download(EbicsOrder.V3.HAA, null, null) { stream -> + val haa = EbicsAdministrative.parseHAA(stream) + logger.debug { + val orders = haa.orders.map(EbicsOrder::description).joinToString(", ") + "HAA: ${orders}" + } + pendingOrders.addAll(haa.orders) + } + // Only fetch requested and supported orders + requestedOrders intersect pendingOrders + } else { + // If there is only one document to fetch, fetching HAA is actually always more expensive + requestedOrders + } + return fetchEbicsDocuments(client, orders, pinnedStartArg) + } + if (transient) { logger.info("Transient mode: fetching once and returning.") val pinnedStartVal = pinnedStart @@ -346,7 +369,7 @@ class EbicsFetch: CliktCommand() { logger.debug("Pinning start date to: {}", pinnedStartVal) dateToInstant(pinnedStartVal) } else null - if (!fetchEbicsDocuments(client, requestedOrders, pinnedStartArg)) { + if (!fetchAvailableDocuments(pinnedStartArg)) { throw ProgramResult(1) } } else { @@ -357,19 +380,7 @@ class EbicsFetch: CliktCommand() { val now = System.currentTimeMillis() if (nextFullRun < now) { logger.info("Running at frequency") - // Always add HAC as it is never announced - val pendingOrders = mutableSetOf<EbicsOrder>(EbicsOrder.V3.HAC) - client.download(EbicsOrder.V3.HAA, null, null) { stream -> - val haa = EbicsAdministrative.parseHAA(stream) - logger.debug { - val orders = haa.orders.map(EbicsOrder::description).joinToString(", ") - "HAA: ${orders}" - } - pendingOrders.addAll(haa.orders) - } - // Only fetch requested and supported orders - val orders = requestedOrders intersect pendingOrders - fetchEbicsDocuments(client, orders, null) + fetchAvailableDocuments(null) nextFullRun = now + cfg.fetch.frequency.toMillis() } val delay = nextFullRun - now