|
22 | 22 | import java.net.URI; |
23 | 23 | import java.nio.file.Path; |
24 | 24 | import java.nio.file.Paths; |
| 25 | +import java.util.ArrayList; |
25 | 26 | import java.util.List; |
26 | 27 | import java.util.Map; |
27 | 28 | import java.util.Objects; |
@@ -303,15 +304,25 @@ private void clearCaches(String connectionId) { |
303 | 304 | fileBindingCache.entrySet().removeIf(e -> e.getValue().isPresent() && e.getValue().get().getConnectionId().equals(connectionId)); |
304 | 305 | } |
305 | 306 |
|
| 307 | + private void handleDeletedConnections(@Nullable WorkspaceSettings oldValue, WorkspaceSettings newValue) { |
| 308 | + if (oldValue != null && !oldValue.getServerConnections().isEmpty()) { |
| 309 | + List<String> deletedConnectionIds = new ArrayList<>(); |
| 310 | + // there used to be connections |
| 311 | + oldValue.getServerConnections().forEach((id, value) -> { |
| 312 | + if (!newValue.getServerConnections().containsKey(id)) { |
| 313 | + // connection was deleted |
| 314 | + deletedConnectionIds.add(id); |
| 315 | + } |
| 316 | + }); |
| 317 | + if (!deletedConnectionIds.isEmpty()) { |
| 318 | + client.removeBindingsForDeletedConnections(deletedConnectionIds); |
| 319 | + } |
| 320 | + } |
| 321 | + } |
| 322 | + |
306 | 323 | @Override |
307 | 324 | public void onChange(@CheckForNull WorkspaceSettings oldValue, WorkspaceSettings newValue) { |
308 | | - if (oldValue != null && oldValue.getServerConnections().size() > newValue.getServerConnections().size()) { |
309 | | - // connection(s) were deleted |
310 | | - var deletedConnections = oldValue.getServerConnections().keySet().stream() |
311 | | - .filter(id -> !newValue.getServerConnections().containsKey(id)) |
312 | | - .toList(); |
313 | | - client.removeBindingsForDeletedConnections(deletedConnections); |
314 | | - } |
| 325 | + handleDeletedConnections(oldValue, newValue); |
315 | 326 | newValue.getServerConnections().forEach((id, value) -> { |
316 | 327 | if (oldValue == null) { |
317 | 328 | // initial sync |
|
0 commit comments