From cfa23fdc23e8699c1e1903f9918c5a57a64f3f94 Mon Sep 17 00:00:00 2001 From: Jon Van Oast Date: Tue, 7 Jan 2025 18:20:08 -0700 Subject: [PATCH] no longer background encounter indexing itself; fix a duplicate rollback/close; timing/debugging on indexing (semi-temporary) --- src/main/java/org/ecocean/Base.java | 3 +++ src/main/java/org/ecocean/Encounter.java | 31 ----------------------- src/main/java/org/ecocean/Occurrence.java | 2 +- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/ecocean/Base.java b/src/main/java/org/ecocean/Base.java index ff94170d5d..8313503d1c 100644 --- a/src/main/java/org/ecocean/Base.java +++ b/src/main/java/org/ecocean/Base.java @@ -106,9 +106,12 @@ public JSONObject opensearchMapping() { public void opensearchIndex() throws IOException { + long startT = System.currentTimeMillis(); OpenSearch opensearch = new OpenSearch(); opensearch.index(this.opensearchIndexName(), this); + long endT = System.currentTimeMillis(); + System.out.println("opensearchIndex(): " + (endT - startT) + "ms indexing " + this); } // this will index "related" objects as needed diff --git a/src/main/java/org/ecocean/Encounter.java b/src/main/java/org/ecocean/Encounter.java index 584e9d70cf..16a2aa8b45 100644 --- a/src/main/java/org/ecocean/Encounter.java +++ b/src/main/java/org/ecocean/Encounter.java @@ -4705,35 +4705,4 @@ public void sendCreationEmails(Shepherd myShepherd, String langCode) { } } - public void opensearchIndexDeep() - throws IOException { - final String encId = this.getId(); - final Encounter origEnc = this; - ExecutorService executor = Executors.newFixedThreadPool(4); - Runnable rn = new Runnable() { - public void run() { - Shepherd bgShepherd = new Shepherd("context0"); - bgShepherd.setAction("Encounter.opensearchIndexDeep_" + encId); - bgShepherd.beginDBTransaction(); - try { - Encounter enc = bgShepherd.getEncounter(encId); - if (enc == null) { - // we use origEnc if we can (especially necessary on initial creation of Encounter) - if (origEnc != null) origEnc.opensearchIndex(); - bgShepherd.rollbackAndClose(); - executor.shutdown(); - return; - } - enc.opensearchIndex(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - bgShepherd.rollbackAndClose(); - } - executor.shutdown(); - } - }; - - executor.execute(rn); - } } diff --git a/src/main/java/org/ecocean/Occurrence.java b/src/main/java/org/ecocean/Occurrence.java index 1f4cce4a65..f267d6cb54 100644 --- a/src/main/java/org/ecocean/Occurrence.java +++ b/src/main/java/org/ecocean/Occurrence.java @@ -1370,7 +1370,7 @@ public void run() { try { Occurrence occur = bgShepherd.getOccurrence(occurId); if ((occur == null) || (occur.getEncounters() == null)) { - bgShepherd.rollbackAndClose(); + // rollbackAndClose handled by finally executor.shutdown(); return; }