Eliminate database calls for filed and reviewed

I learned map projections and list comprehensions in cypher tonight!
🎉 So much wow!
This commit is contained in:
roschaefer 2019-12-06 01:57:49 +01:00
parent 942e74163e
commit 2f2bf571ed

View File

@ -66,14 +66,17 @@ export default {
const reportReadTxPromise = session.readTransaction(async tx => {
const allReportsTransactionResponse = await tx.run(
`
MATCH (submitter:User)-[filed:FILED]->(report:Report)-[:BELONGS_TO]->(resource)
MATCH (report:Report)-[:BELONGS_TO]->(resource)
WHERE resource:User OR resource:Post OR resource:Comment
RETURN DISTINCT report, resource, labels(resource)[0] as type
WITH report, resource,
[(submitter:User)-[filed:FILED]->(report) | filed {.*, submitter: properties(submitter)} ] as filed,
[(moderator:User)-[reviewed:REVIEWED]->(report) | reviewed {.*, moderator: properties(moderator)} ] as reviewed,
resource {.*, __typename: labels(resource)[0] } as resourceWithType
RETURN report {.*, resource: resourceWithType, filed: filed, reviewed: reviewed}
${orderByClause}
`,
{},
)
return allReportsTransactionResponse.records.map(transformReturnType)
return allReportsTransactionResponse.records.map(record => record.get('report'))
})
try {
const txResult = await reportReadTxPromise