Skip to content

Commit

Permalink
[3638] Avoid hitting the DB in the common case in getOrCreateECEP
Browse files Browse the repository at this point in the history
Bug: #3638
Signed-off-by: Pierre-Charles David <[email protected]>
  • Loading branch information
pcdavid committed Jun 18, 2024
1 parent 62d42d0 commit 3973da5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ image:doc/screenshots/insideLabelPositions.png[Inside label positions, 70%]
- https://github.com/eclipse-sirius/sirius-web/issues/3623[#3623] [form] Remove unused form payload
- https://github.com/eclipse-sirius/sirius-web/issues/3627[#3627] [form] Remove unused mutation in form
- https://github.com/eclipse-sirius/sirius-web/issues/3606[#3606] [test] Improve error handling in ExecuteEditingContextFunctionRunner and ExecuteEditingContextFunctionEventHandler
- https://github.com/eclipse-sirius/sirius-web/issues/3638[#3638] [core] Avoid hitting the database when dispatch inputs to the proper editing context

== v2024.5.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -77,31 +77,28 @@ public Mono<IPayload> dispatchEvent(String editingContextId, IInput input) {

@Override
public synchronized Optional<IEditingContextEventProcessor> getOrCreateEditingContextEventProcessor(String editingContextId) {
Optional<IEditingContextEventProcessor> optionalEditingContextEventProcessor = Optional.empty();
if (this.editingContextSearchService.existsById(editingContextId)) {
optionalEditingContextEventProcessor = Optional.ofNullable(this.editingContextEventProcessors.get(editingContextId))
.map(EditingContextEventProcessorEntry::getEditingContextEventProcessor);
if (optionalEditingContextEventProcessor.isEmpty()) {
Optional<IEditingContext> optionalEditingContext = this.editingContextSearchService.findById(editingContextId);
if (optionalEditingContext.isPresent()) {
IEditingContext editingContext = optionalEditingContext.get();

var editingContextEventProcessor = this.editingContextEventProcessorFactory.createEditingContextEventProcessor(editingContext);
Disposable subscription = editingContextEventProcessor.canBeDisposed().delayElements(this.disposeDelay).subscribe(canBeDisposed -> {
// We will wait for the delay before trying to dispose the editing context event processor
// We will check if the editing context event processor is still empty
if (canBeDisposed.booleanValue() && editingContextEventProcessor.getRepresentationEventProcessors().isEmpty()) {
this.disposeEditingContextEventProcessor(editingContextId);
} else {
this.logger.trace("Stopping the disposal of the editing context");
}
});

var editingContextEventProcessorEntry = new EditingContextEventProcessorEntry(editingContextEventProcessor, subscription);
this.editingContextEventProcessors.put(editingContextId, editingContextEventProcessorEntry);

optionalEditingContextEventProcessor = Optional.of(editingContextEventProcessor);
}
Optional<IEditingContextEventProcessor> optionalEditingContextEventProcessor = Optional.ofNullable(this.editingContextEventProcessors.get(editingContextId))
.map(EditingContextEventProcessorEntry::getEditingContextEventProcessor);
if (optionalEditingContextEventProcessor.isEmpty()) {
Optional<IEditingContext> optionalEditingContext = this.editingContextSearchService.findById(editingContextId);
if (optionalEditingContext.isPresent()) {
IEditingContext editingContext = optionalEditingContext.get();

var editingContextEventProcessor = this.editingContextEventProcessorFactory.createEditingContextEventProcessor(editingContext);
Disposable subscription = editingContextEventProcessor.canBeDisposed().delayElements(this.disposeDelay).subscribe(canBeDisposed -> {
// We will wait for the delay before trying to dispose the editing context event processor
// We will check if the editing context event processor is still empty
if (canBeDisposed.booleanValue() && editingContextEventProcessor.getRepresentationEventProcessors().isEmpty()) {
this.disposeEditingContextEventProcessor(editingContextId);
} else {
this.logger.trace("Stopping the disposal of the editing context");
}
});

var editingContextEventProcessorEntry = new EditingContextEventProcessorEntry(editingContextEventProcessor, subscription);
this.editingContextEventProcessors.put(editingContextId, editingContextEventProcessorEntry);

optionalEditingContextEventProcessor = Optional.of(editingContextEventProcessor);
}
}

Expand Down

0 comments on commit 3973da5

Please sign in to comment.