Skip to content

Commit

Permalink
Merge pull request #976 from WildMeOrg/974_new_encounter_indexing
Browse files Browse the repository at this point in the history
no longer background encounter indexing itself
  • Loading branch information
holmbergius authored Jan 8, 2025
2 parents 023135f + cfa23fd commit d0a9ac7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/ecocean/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/org/ecocean/Encounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/ecocean/Occurrence.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit d0a9ac7

Please sign in to comment.