Skip to content

Commit

Permalink
Merge pull request #785 from oskarhane/fix-meta-query
Browse files Browse the repository at this point in the history
Fix meta query to be more performant
  • Loading branch information
pe4cey authored Jun 19, 2018
2 parents 1eecb27 + 31f80e0 commit 163da49
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 56 deletions.
37 changes: 16 additions & 21 deletions src/shared/modules/dbMeta/dbMetaDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const getServerConfig = (state, includePrefixes = []) => {
function updateMetaForContext (state, meta, context) {
const notInCurrentContext = e => e.context !== context
const mapResult = (metaIndex, mapFunction) =>
meta.records[metaIndex].get(1).map(mapFunction)
meta.records[metaIndex].get(0).data.map(mapFunction)
const mapSingleValue = r => ({ val: r, context })
const mapInteger = r => (bolt.neo4j.isInt(r) ? r.toNumber() || 0 : r || 0)
const mapInvocableValue = r => {
Expand Down Expand Up @@ -156,10 +156,10 @@ function updateMetaForContext (state, meta, context) {
.filter(notInCurrentContext)
.concat(mapResult(4, mapInvocableValue))
const nodes = meta.records[5]
? mapInteger(meta.records[5].get(1))
? mapInteger(meta.records[5].get(0).data)
: state.nodes
const relationships = meta.records[6]
? mapInteger(meta.records[6].get(1))
? mapInteger(meta.records[6].get(0).data)
: state.relationships

return {
Expand Down Expand Up @@ -259,28 +259,23 @@ export const updateSettings = settings => {
// Epics
export const metaQuery = `
CALL db.labels() YIELD label
WITH COLLECT(label)[..1000] AS labels
RETURN 'labels' as a, labels as result
UNION
RETURN {name:'labels', data:COLLECT(label)[..1000]} as result
UNION ALL
CALL db.relationshipTypes() YIELD relationshipType
WITH COLLECT(relationshipType)[..1000] AS relationshipTypes
RETURN 'relationshipTypes' as a, relationshipTypes as result
UNION
RETURN {name:'relationshipTypes', data:COLLECT(relationshipType)[..1000]} as result
UNION ALL
CALL db.propertyKeys() YIELD propertyKey
WITH COLLECT(propertyKey)[..1000] AS propertyKeys
RETURN 'propertyKeys' as a, propertyKeys as result
UNION
RETURN {name:'propertyKeys', data:COLLECT(propertyKey)[..1000]} as result
UNION ALL
CALL dbms.functions() YIELD name, signature, description
WITH collect({name: name, signature: signature, description: description}) as functions
RETURN 'functions' as a, functions AS result
UNION
RETURN {name:'functions', data: collect({name: name, signature: signature, description: description})} AS result
UNION ALL
CALL dbms.procedures() YIELD name, signature, description
WITH collect({name: name, signature: signature, description: description}) as procedures
RETURN 'procedures' as a, procedures as result
UNION
MATCH (n) RETURN 'nodes' AS a, count(n) AS result
UNION
MATCH ()-[]->() RETURN 'relationships' AS a, count(*) AS result
RETURN {name:'procedures', data:collect({name: name, signature: signature, description: description})} as result
UNION ALL
MATCH () RETURN { name:'nodes', data:count(*) } AS result
UNION ALL
MATCH ()-[]->() RETURN { name:'relationships', data: count(*)} AS result
`

export const dbMetaEpic = (some$, store) =>
Expand Down
78 changes: 43 additions & 35 deletions src/shared/modules/dbMeta/dbMetaDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,62 @@ describe('hydrating state', () => {
describe('updating metadata', () => {
test('should update state when metadata is updated', () => {
const returnedLabels = {
a: 'labels',
result: { name: 'labels' },
get: () => {
return ['label1', 'label2']
return { data: ['label1', 'label2'] }
}
}
const returnedRelationshipTypes = {
a: 'relationshipTypes',
result: { name: 'relationshipTypes' },
get: () => {
return ['rel1', 'rel2']
return { data: ['rel1', 'rel2'] }
}
}
const returnedProperties = {
a: 'properties',
result: { name: 'properties' },
get: () => {
return ['prop1', 'prop2']
return { data: ['prop1', 'prop2'] }
}
}
const returnedFunctions = {
a: 'functions',
result: { name: 'functions' },
get: () => {
return [
{
name: 'ns.functionName',
signature: 'functionSignature',
description: 'functionDescription'
}
]
return {
data: [
{
name: 'ns.functionName',
signature: 'functionSignature',
description: 'functionDescription'
}
]
}
}
}
const returnedProcedures = {
a: 'procedures',
result: { name: 'procedures' },
get: () => {
return [
{
name: 'ns.procedureName',
signature: 'procedureSignature',
description: 'procedureDescription'
}
]
return {
data: [
{
name: 'ns.procedureName',
signature: 'procedureSignature',
description: 'procedureDescription'
}
]
}
}
}
const returnedNodes = {
a: 'nodes',
get: () => neo4j.int(5)
result: { name: 'nodes' },
get: () => ({
data: neo4j.int(5)
})
}
const returnedRelationships = {
a: 'relationships',
get: () => neo4j.int(10)
result: { name: 'relationships' },
get: () => ({
data: neo4j.int(10)
})
}

const action = {
Expand Down Expand Up @@ -139,19 +147,19 @@ describe('updating metadata', () => {
})

test('should update state with empty metadata', () => {
const returnNothing = () => []
const returnNull = () => null
const returnNothing = () => ({ data: [] })
const returnNull = () => ({ data: null })
const action = {
type: meta.UPDATE_META,
meta: {
records: [
{ a: 'labels', get: returnNothing },
{ a: 'relationshipTypes', get: returnNothing },
{ a: 'properties', get: returnNothing },
{ a: 'functions', get: returnNothing },
{ a: 'procedures', get: returnNothing },
{ a: 'nodes', get: returnNull },
{ a: 'realtionships', get: returnNull }
{ result: { name: 'labels' }, get: returnNothing },
{ result: { name: 'relationshipTypes' }, get: returnNothing },
{ result: { name: 'properties' }, get: returnNothing },
{ result: { name: 'functions' }, get: returnNothing },
{ result: { name: 'procedures' }, get: returnNothing },
{ result: { name: 'nodes' }, get: returnNull },
{ result: { name: 'realtionships' }, get: returnNull }
]
},
context: 'mycontext'
Expand Down

0 comments on commit 163da49

Please sign in to comment.