Skip to content

Commit

Permalink
Optimize CnaEvent lookup and storage in CnaUtil
Browse files Browse the repository at this point in the history
This commit improves the performance of the storeCnaEvents method by
replacing the stream-based lookup with a HashSet contains check. This
change reduces the computational complexity from O(n) to O(1) for the
lookup operation, resulting in a significant performance gain when
processing large collections of CnaEvent objects.
  • Loading branch information
sgicbpc authored and sgicbpc committed Dec 5, 2023
1 parent 1fe20d9 commit 9ce5721
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/java/org/mskcc/cbio/portal/util/CnaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ public static void storeCnaEvents(
if (!CNA.AMP.equals(cnaEvent.getAlteration()) && !CNA.HOMDEL.equals(cnaEvent.getAlteration())) {
continue;
}
Optional<CnaEvent.Event> existingCnaEvent = existingCnaEvents
.stream()
.filter(e -> e.equals(cnaEvent.getEvent()))
.findFirst();
if (existingCnaEvent.isPresent()) {
cnaEvent.setEventId(existingCnaEvent.get().getEventId());

CnaEvent.Event event = cnaEvent.getEvent()
if (existingCnaEvents.contains(event)) {
cnaEvent.setEventId(event.getEventId());
DaoCnaEvent.addCaseCnaEvent(cnaEvent, false);
} else {
DaoCnaEvent.addCaseCnaEvent(cnaEvent, true);
existingCnaEvents.add(cnaEvent.getEvent());
existingCnaEvents.add(event);
}
}
}
Expand Down

0 comments on commit 9ce5721

Please sign in to comment.