Skip to content

Commit

Permalink
Optimize performance to not make an additional queries
Browse files Browse the repository at this point in the history
  • Loading branch information
SerhiiNosko committed Dec 12, 2024
1 parent ea4e394 commit d982a27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"invoice.invoice-lines.item.put",
"invoices.acquisition-units.bypass.execute",
"orders-storage.order-invoice-relationships.collection.get",
"orders-storage.settings.collection.get",
"consortia.user-tenants.collection.get",
"user-tenants.collection.get",
"consortia.sharing-instances.item.post"
Expand Down Expand Up @@ -2151,6 +2152,7 @@
"organizations-storage.organizations.collection.get",
"organizations-storage.organizations.item.get",
"isbn-utils.convert-to-13.get",
"orders-storage.settings.collection.get",
"consortia.user-tenants.collection.get",
"user-tenants.collection.get",
"consortia.sharing-instances.collection.get",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ public Future<RequestContext> overrideContextToCentralTenantIfNeeded(RequestCont
return Future.succeededFuture(requestContext);
}
RequestContext centralContext = createContextWithNewTenantId(requestContext, configuration.centralTenantId());
return settingsRetriever.getSettingByKey(SettingKey.CENTRAL_ORDERING_ENABLED, centralContext)
.map(centralOrdering -> {
logger.info("overrideContextToCentralTenantIdNeeded:: central ordering enabled: {}", centralOrdering);
return centralOrdering.map(Setting::getValue).orElse(null);
})
.compose(orderingEnabled -> Future.succeededFuture(Boolean.parseBoolean(orderingEnabled) ? centralContext : requestContext));
return isCentralOrderingEnabled(requestContext)
.compose(orderingEnabled -> Future.succeededFuture(orderingEnabled ? centralContext : requestContext));
});
}

public Future<Boolean> isCentralOrderingEnabled(RequestContext requestContext) {
return settingsRetriever.getSettingByKey(SettingKey.CENTRAL_ORDERING_ENABLED, requestContext)
.map(centralOrdering -> {
logger.info("isCentralOrderingEnabled:: central ordering enabled: {}", centralOrdering);
return centralOrdering.map(setting -> Boolean.parseBoolean(setting.getValue())).orElse(false);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,10 @@ private Future<List<String>> getUserTenantsIfNeeded(RequestContext requestContex
return consortiumConfigurationService.getConsortiumConfiguration(requestContext)
.compose(consortiumConfiguration ->
consortiumConfiguration
.map(configuration -> consortiumUserTenantsRetriever.getUserTenants(configuration.consortiumId(), configuration.centralTenantId(), requestContext))
.map(configuration -> consortiumConfigurationService.isCentralOrderingEnabled(requestContext)
.compose(isCentralOrderingEnabled -> isCentralOrderingEnabled
? consortiumUserTenantsRetriever.getUserTenants(configuration.consortiumId(), configuration.centralTenantId(), requestContext)
: Future.succeededFuture()))
.orElse(Future.succeededFuture())
);
}
Expand Down

0 comments on commit d982a27

Please sign in to comment.