From dedb97166bf4fa48b19ad6cabef87182506c64b1 Mon Sep 17 00:00:00 2001 From: reusedname <155286845+reusedname@users.noreply.github.com> Date: Tue, 25 Feb 2025 23:21:43 +0500 Subject: [PATCH] Fix group precondition not respecting priority --- .../ctbrec/recorder/RecordingPreconditions.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java b/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java index 3a82a1f5..bffbed64 100644 --- a/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java +++ b/common/src/main/java/ctbrec/recorder/RecordingPreconditions.java @@ -175,22 +175,27 @@ public class RecordingPreconditions { return; } - for (String modelUrl : modelGroup.get().getModelUrls()) { - if (modelUrl.equals(model.getUrl())) { + for (var groupModel : modelGroup.get().getModelUrls().stream() + .map(modelUrl -> getModelForUrl(modelUrl)) + .filter(x -> x.isPresent()) + .map(x -> x.get()) + .sorted((l, r) -> Integer.compare(r.getPriority(), l.getPriority())) // high to low + .toList()) { + if (model.getUrl().equals(groupModel.getUrl())) { // no other model with higher prio is online, start recording // but before that stop all recordings of models with lower prio stopModelsWithLowerPrio(modelGroup.get()); return; } else { - Optional otherModel = getModelForUrl(modelUrl); + Optional otherModel = getModelForUrl(groupModel.getUrl()); if (otherModel.isPresent()) { - if (otherModelIsRecorded(otherModel.get())) { + if (!otherModel.get().isSuspended() && otherModelIsRecorded(otherModel.get())) { throw new PreconditionNotMetException(otherModel.get() + " from the same group is already recorded"); } else if (otherModelCanBeRecorded(otherModel.get())) { throw new PreconditionNotMetException(otherModel.get() + " from the same group can be recorded"); } } else { - LOG.warn("Couldn't check if model from same group has higer prio for {}", modelUrl); + LOG.warn("Couldn't check if model from same group has higer prio for {}", groupModel.getUrl()); } } }