Skip to content

Commit

Permalink
Only dispatch parent metrics update event when metrics of current pro…
Browse files Browse the repository at this point in the history
…ject actually changed.

Signed-off-by: Ralf King <[email protected]>
  • Loading branch information
rkg-mm committed May 6, 2024
1 parent e0ea31c commit 0cfdd8c
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Map;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -94,8 +95,10 @@ private void updateMetrics(final UUID uuid) throws Exception {
case HIGHEST_SEMVER_CHILD -> this.updateHighestSemVerChildCollectionMetrics(project, pm, counters);
}

AtomicBoolean metricsChanged = new AtomicBoolean(false);
qm.runInTransaction(() -> {
final ProjectMetrics latestMetrics = qm.getMostRecentProjectMetrics(project);
metricsChanged.set(counters.hasChanged(latestMetrics));
if (!counters.hasChanged(latestMetrics)) {
LOGGER.debug("Metrics of project " + uuid + " did not change");
latestMetrics.setLastOccurrence(counters.measuredAt);
Expand All @@ -116,7 +119,7 @@ private void updateMetrics(final UUID uuid) throws Exception {
DurationFormatUtils.formatDuration(new Date().getTime() - counters.measuredAt.getTime(), "mm:ss:SS"));

Project parent = project.getParent();
if(parent != null && parent.getCollectionLogic() != ProjectCollectionLogic.NONE) {
if(parent != null && parent.getCollectionLogic() != ProjectCollectionLogic.NONE && metricsChanged.get()) {
LOGGER.debug("Scheduling metrics update of project's parent collection " + parent.getUuid());
Event.dispatch(new ProjectMetricsUpdateEvent(parent.getUuid()));
}
Expand Down

0 comments on commit 0cfdd8c

Please sign in to comment.