Skip to content

Commit 9805102

Browse files
committed
Reduce number of queries to a single one for :schema
1 parent c439d9c commit 9805102

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

app/scripts/services/Bolt.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ angular.module('neo4jApp.services')
198198
else
199199
indexString = "Indexes"
200200
for index in indexes
201-
indexString += "\n #{index.get('description').replace('INDEX','')} #{index.get('state').toUpperCase()}"
202-
if index.get("type") == "node_unique_property"
201+
indexString += "\n #{index.description.replace('INDEX','')} #{index.state.toUpperCase()}"
202+
if index.type == "node_unique_property"
203203
indexString += " (for uniqueness constraint)"
204204
if (constraints.length == 0)
205205
constraintsString = "No constraints"
206206
else
207207
constraintsString = "Constraints"
208208
for constraint in constraints
209-
constraintsString += "\n #{constraint.get('description').replace('CONSTRAINT','')}"
209+
constraintsString += "\n #{constraint.description.replace('CONSTRAINT','')}"
210210
return "#{indexString}\n\n#{constraintsString}\n"
211211

212212
boltResultToRESTResult = (result) ->

app/scripts/services/UtilityBolt.coffee

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ angular.module('neo4jApp.services')
3030
clearConnection: -> Bolt.clearConnection()
3131
getSchema: ->
3232
q = $q.defer()
33-
$q.all([
34-
Bolt.callProcedure("db.indexes"),
35-
Bolt.callProcedure("db.constraints"),
36-
]).then((data) ->
37-
q.resolve(Bolt.constructSchemaResult data[0], data[1])
38-
)
33+
Bolt.boltTransaction(
34+
"CALL db.indexes() YIELD description, state, type " +
35+
"WITH COLLECT({description: description, state: state, type: type}) AS indexes " +
36+
"RETURN 'indexes' AS name, indexes AS items " +
37+
"UNION " +
38+
"CALL db.constraints() YIELD description " +
39+
"WITH COLLECT({description: description}) AS constraints " +
40+
"RETURN 'constraints' AS name, constraints AS items"
41+
).promise.then((result) ->
42+
return q.resolve(Bolt.constructSchemaResult([], [])) unless result.records.length
43+
q.resolve(Bolt.constructSchemaResult result.records[0].get('items'), result.records[1].get('items'))
44+
).catch( (e) -> q.reject Bolt.constructResult e)
3945
q.promise
4046

4147
getMeta: ->

0 commit comments

Comments
 (0)