Skip to content

Commit

Permalink
Initialise GraphCatalogProcedureFacade only with what it needs
Browse files Browse the repository at this point in the history
  • Loading branch information
vnickolov committed Sep 5, 2024
1 parent 052de7f commit 8f0d3d6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void accept(AutoCloseable autoCloseable) {
graphDatabaseService,
graphProjectMemoryUsageService,
transactionContext,
applicationsFacade,
applicationsFacade.graphCatalog(),
writeContext,
procedureReturnColumns,
databaseModeRestriction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.gds.procedures.catalog;

import org.neo4j.gds.api.ProcedureReturnColumns;
import org.neo4j.gds.applications.ApplicationsFacade;
import org.neo4j.gds.applications.algorithms.machinery.MemoryEstimateResult;
import org.neo4j.gds.applications.algorithms.machinery.RequestScopedDependencies;
import org.neo4j.gds.applications.algorithms.machinery.WriteContext;
Expand Down Expand Up @@ -84,7 +83,7 @@ public class GraphCatalogProcedureFacade {
private final DatabaseModeRestriction databaseModeRestriction;

// business facade
private final ApplicationsFacade applicationsFacade;
private final GraphCatalogApplications catalog;

/**
* @param streamCloser A special thing needed for property streaming
Expand All @@ -95,7 +94,7 @@ public GraphCatalogProcedureFacade(
GraphDatabaseService graphDatabaseService,
GraphProjectMemoryUsageService graphProjectMemoryUsageService,
TransactionContext transactionContext,
ApplicationsFacade applicationsFacade,
GraphCatalogApplications catalog,
WriteContext writeContext,
ProcedureReturnColumns procedureReturnColumns,
DatabaseModeRestriction databaseModeRestriction
Expand All @@ -106,7 +105,7 @@ public GraphCatalogProcedureFacade(
this.graphProjectMemoryUsageService = graphProjectMemoryUsageService;
this.transactionContext = transactionContext;

this.applicationsFacade = applicationsFacade;
this.catalog = catalog;
this.writeContext = writeContext;
this.procedureReturnColumns = procedureReturnColumns;
this.databaseModeRestriction = databaseModeRestriction;
Expand All @@ -131,7 +130,7 @@ public <RETURN_TYPE> RETURN_TYPE graphExists(String graphName, Function<Boolean,
}

public boolean graphExists(String graphName) {
return catalog().graphExists(
return catalog.graphExists(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName
Expand All @@ -150,7 +149,7 @@ public Stream<GraphInfo> dropGraph(
String databaseName,
String username
) throws IllegalArgumentException {
var results = catalog().dropGraph(
var results = catalog.dropGraph(
graphNameOrListOfGraphNames,
failIfMissing,
databaseName,
Expand All @@ -171,7 +170,7 @@ public Stream<GraphInfoWithHistogram> listGraphs(String graphName) {

var displayDegreeDistribution = procedureReturnColumns.contains("degreeDistribution");

var results = catalog().listGraphs(
var results = catalog.listGraphs(
requestScopedDependencies.getUser(),
graphName,
displayDegreeDistribution,
Expand All @@ -195,7 +194,7 @@ public Stream<GraphProjectNativeResult> nativeProject(
Object relationshipProjection,
Map<String, Object> configuration
) {
var result = catalog().nativeProject(
var result = catalog.nativeProject(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphDatabaseService,
Expand All @@ -219,7 +218,7 @@ public Stream<MemoryEstimateResult> estimateNativeProject(
Object relationshipProjection,
Map<String, Object> configuration
) {
var result = catalog().estimateNativeProject(
var result = catalog.estimateNativeProject(
requestScopedDependencies.getDatabaseId(),
graphProjectMemoryUsageService,
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -240,7 +239,7 @@ public Stream<GraphProjectCypherResult> cypherProject(
String relationshipQuery,
Map<String, Object> configuration
) {
var result = catalog().cypherProject(
var result = catalog.cypherProject(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphDatabaseService,
Expand All @@ -263,7 +262,7 @@ public Stream<MemoryEstimateResult> estimateCypherProject(
String relationshipQuery,
Map<String, Object> configuration
) {
var result = catalog().estimateCypherProject(
var result = catalog.estimateCypherProject(
requestScopedDependencies.getDatabaseId(),
graphProjectMemoryUsageService,
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -285,7 +284,7 @@ public Stream<GraphFilterResult> subGraphProject(
String relationshipFilter,
Map<String, Object> configuration
) {
var result = catalog().subGraphProject(
var result = catalog.subGraphProject(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -301,7 +300,7 @@ public Stream<GraphFilterResult> subGraphProject(
}

public Stream<GraphMemoryUsage> sizeOf(String graphName) {
var result = catalog().sizeOf(
var result = catalog.sizeOf(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName
Expand All @@ -315,7 +314,7 @@ public Stream<GraphDropNodePropertiesResult> dropNodeProperties(
Object nodeProperties,
Map<String, Object> configuration
) {
var result = catalog().dropNodeProperties(
var result = catalog.dropNodeProperties(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -332,7 +331,7 @@ public Stream<GraphDropRelationshipResult> dropRelationships(
String graphName,
String relationshipType
) {
var result = catalog().dropRelationships(
var result = catalog.dropRelationships(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -349,7 +348,7 @@ public Stream<GraphDropGraphPropertiesResult> dropGraphProperty(
String graphProperty,
Map<String, Object> configuration
) {
var numberOfPropertiesRemoved = catalog().dropGraphProperty(
var numberOfPropertiesRemoved = catalog.dropGraphProperty(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName,
Expand All @@ -371,7 +370,7 @@ public Stream<MutateLabelResult> mutateNodeLabel(
String nodeLabel,
Map<String, Object> configuration
) {
var result = catalog().mutateNodeLabel(
var result = catalog.mutateNodeLabel(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName,
Expand All @@ -387,7 +386,7 @@ public Stream<StreamGraphPropertyResult> streamGraphProperty(
String graphProperty,
Map<String, Object> configuration
) {
var result = catalog().streamGraphProperty(
var result = catalog.streamGraphProperty(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName,
Expand Down Expand Up @@ -442,7 +441,7 @@ private <T> Stream<T> streamNodePropertyOrProperties(
) {
var usesPropertyNameColumn = procedureReturnColumns.contains("nodeProperty");

var resultStream = catalog().streamNodeProperties(
var resultStream = catalog.streamNodeProperties(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand Down Expand Up @@ -500,7 +499,7 @@ public Stream<TopologyResult> streamRelationships(
Object relationshipTypes,
Map<String, Object> configuration
) {
return catalog().streamRelationships(
return catalog.streamRelationships(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName,
Expand All @@ -515,7 +514,7 @@ public Stream<NodePropertiesWriteResult> writeNodeProperties(
Object nodeLabels,
Map<String, Object> configuration
) {
var result = catalog().writeNodeProperties(
var result = catalog.writeNodeProperties(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
writeContext.nodePropertyExporterBuilder(),
Expand All @@ -537,7 +536,7 @@ public Stream<WriteRelationshipPropertiesResult> writeRelationshipProperties(
List<String> relationshipProperties,
Map<String, Object> configuration
) {
var result = catalog().writeRelationshipProperties(
var result = catalog.writeRelationshipProperties(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
writeContext.relationshipPropertiesExporterBuilder(),
Expand All @@ -556,7 +555,7 @@ public Stream<WriteLabelResult> writeNodeLabel(
String nodeLabel,
Map<String, Object> configuration
) {
var result = catalog().writeNodeLabel(
var result = catalog.writeNodeLabel(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
writeContext.nodeLabelExporterBuilder(),
Expand All @@ -575,7 +574,7 @@ public Stream<WriteRelationshipResult> writeRelationships(
String relationshipProperty,
Map<String, Object> configuration
) {
var result = catalog().writeRelationships(
var result = catalog.writeRelationships(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
writeContext.relationshipExporterBuilder(),
Expand All @@ -596,7 +595,7 @@ public Stream<RandomWalkSamplingResult> sampleRandomWalkWithRestarts(
String originGraphName,
Map<String, Object> configuration
) {
var result = catalog().sampleRandomWalkWithRestarts(
var result = catalog.sampleRandomWalkWithRestarts(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -614,7 +613,7 @@ public Stream<RandomWalkSamplingResult> sampleCommonNeighbourAwareRandomWalk(
String originGraphName,
Map<String, Object> configuration
) {
var result = catalog().sampleCommonNeighbourAwareRandomWalk(
var result = catalog.sampleCommonNeighbourAwareRandomWalk(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -631,7 +630,7 @@ public Stream<MemoryEstimateResult> estimateCommonNeighbourAwareRandomWalk(
String graphName,
Map<String, Object> configuration
) {
var result = catalog().estimateCommonNeighbourAwareRandomWalk(
var result = catalog.estimateCommonNeighbourAwareRandomWalk(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName,
Expand All @@ -645,13 +644,13 @@ public Stream<FileExportResult> exportToCsv(
String graphName,
Map<String, Object> configuration
) {
var result = catalog().exportToCsv(graphName, configuration);
var result = catalog.exportToCsv(graphName, configuration);

return Stream.of(result);
}

public Stream<MemoryEstimateResult> exportToCsvEstimate(String graphName, Map<String, Object> configuration) {
var result = catalog().exportToCsvEstimate(graphName, configuration);
var result = catalog.exportToCsvEstimate(graphName, configuration);

return Stream.of(result);
}
Expand All @@ -662,7 +661,7 @@ public Stream<DatabaseExportResult> exportToDatabase(
) {
databaseModeRestriction.ensureNotOnCluster();

var result = catalog().exportToDatabase(graphName, configuration);
var result = catalog.exportToDatabase(graphName, configuration);

return Stream.of(result);
}
Expand All @@ -673,7 +672,7 @@ public Stream<GraphGenerationStats> generateGraph(
long averageDegree,
Map<String, Object> configuration
) {
var result = catalog().generateGraph(
var result = catalog.generateGraph(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
graphName,
Expand All @@ -694,7 +693,7 @@ private <T> Stream<T> streamRelationshipPropertyOrProperties(
) {
var usesPropertyNameColumn = procedureReturnColumns.contains("relationshipProperty");

var resultStream = catalog().streamRelationshipProperties(
var resultStream = catalog.streamRelationshipProperties(
requestScopedDependencies.getUser(),
requestScopedDependencies.getDatabaseId(),
requestScopedDependencies.getTaskRegistryFactory(),
Expand All @@ -720,8 +719,4 @@ private String validateValue(String graphName) {

return graphName;
}

private GraphCatalogApplications catalog() {
return applicationsFacade.graphCatalog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void shouldDetermineIfGraphExists() {
null,
null,
null,
new ApplicationsFacadeBuilder().with(businessFacade).build(),
new ApplicationsFacadeBuilder().with(businessFacade).build().graphCatalog(),
WriteContext.builder().build(),
null,
null
Expand Down Expand Up @@ -108,7 +108,7 @@ void shouldListGraphsWithoutDegreeDistribution() {
null,
null,
null,
new ApplicationsFacadeBuilder().with(businessFacade).build(),
new ApplicationsFacadeBuilder().with(businessFacade).build().graphCatalog(),
procedureContext,
procedureReturnColumns,
null
Expand Down Expand Up @@ -145,7 +145,7 @@ void shouldListGraphsWithDegreeDistribution() {
null,
null,
null,
new ApplicationsFacadeBuilder().with(businessFacade).build(),
new ApplicationsFacadeBuilder().with(businessFacade).build().graphCatalog(),
procedureContext,
procedureReturnColumns,
null
Expand Down Expand Up @@ -194,7 +194,7 @@ void shouldListGraphsWithoutMemoryUsage() {
null,
null,
null,
new ApplicationsFacadeBuilder().with(businessFacade).build(),
new ApplicationsFacadeBuilder().with(businessFacade).build().graphCatalog(),
procedureContext,
procedureReturnColumns,
null
Expand Down Expand Up @@ -234,7 +234,7 @@ void shouldListGraphsWithMemoryUsage(String returnColumn) {
null,
null,
null,
new ApplicationsFacadeBuilder().with(businessFacade).build(),
new ApplicationsFacadeBuilder().with(businessFacade).build().graphCatalog(),
procedureContext,
procedureReturnColumns,
null
Expand Down

0 comments on commit 8f0d3d6

Please sign in to comment.