-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add postSaveHook #39306
chore: add postSaveHook #39306
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,12 @@ public class DatasourceStorage extends GitSyncedDomain { | |
@Transient | ||
Boolean isMock; | ||
|
||
@Transient | ||
String tenantId; | ||
|
||
@Transient | ||
String instanceId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if DatasourceStorage should have these fields configured in the POJO. I understand that we need the fields What do you think of instead introducing a map of parameters that can store this metadata that is parsed by the plugin itself? Would that be more extendable? Or do you think it'll lead to confusion and lack of clarity in the code? |
||
|
||
public DatasourceStorage( | ||
String datasourceId, | ||
String environmentId, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -183,6 +183,16 @@ public Mono<DatasourceStorage> executePreSaveActions(DatasourceStorage datasourc | |||||||||||||||||||||
return pluginExecutorMono.flatMap(pluginExecutor -> pluginExecutor.preSaveHook(datasourceStorage)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
public Mono<DatasourceStorage> executePostSaveActions(DatasourceStorage datasourceStorage) { | ||||||||||||||||||||||
Mono<Plugin> pluginMono = pluginService.findById(datasourceStorage.getPluginId()); | ||||||||||||||||||||||
Mono<PluginExecutor> pluginExecutorMono = pluginExecutorHelper | ||||||||||||||||||||||
.getPluginExecutor(pluginMono) | ||||||||||||||||||||||
.switchIfEmpty(Mono.error(new AppsmithException( | ||||||||||||||||||||||
AppsmithError.NO_RESOURCE_FOUND, FieldName.PLUGIN, datasourceStorage.getPluginId()))); | ||||||||||||||||||||||
|
||||||||||||||||||||||
return pluginExecutorMono.flatMap(pluginExecutor -> pluginExecutor.postSaveHook(datasourceStorage)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
@Override | ||||||||||||||||||||||
public Mono<DatasourceStorage> validateDatasourceStorage(DatasourceStorage datasourceStorage) { | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -242,7 +252,10 @@ private Mono<DatasourceStorage> validateAndSaveDatasourceStorageToRepository( | |||||||||||||||||||||
unsavedDatasourceStorage.updateForBulkWriteOperation(); | ||||||||||||||||||||||
return Mono.just(unsavedDatasourceStorage); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return repository.save(unsavedDatasourceStorage).thenReturn(unsavedDatasourceStorage); | ||||||||||||||||||||||
return repository | ||||||||||||||||||||||
.save(unsavedDatasourceStorage) | ||||||||||||||||||||||
.then(this.executePostSaveActions(unsavedDatasourceStorage)) | ||||||||||||||||||||||
.thenReturn(unsavedDatasourceStorage); | ||||||||||||||||||||||
Comment on lines
+255
to
+258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider transaction boundary for save operation. The save operation and post-save actions should be executed within a transaction to ensure atomicity. If the post-save action fails, the save should be rolled back. Consider using Spring's -return repository
- .save(unsavedDatasourceStorage)
- .then(this.executePostSaveActions(unsavedDatasourceStorage))
- .thenReturn(unsavedDatasourceStorage);
+return transactionTemplate.execute(status -> {
+ return repository
+ .save(unsavedDatasourceStorage)
+ .then(this.executePostSaveActions(unsavedDatasourceStorage))
+ .thenReturn(unsavedDatasourceStorage);
+}); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
}); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Update
prepareTransientFields
to include new fields.The new transient fields
tenantId
andinstanceId
should be initialized in theprepareTransientFields
method to maintain consistency with other transient fields.Apply this diff to update the method:
📝 Committable suggestion