From 2f2bf571ed0964f7ef39b668c8ab9ae29e95f6a4 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Fri, 6 Dec 2019 01:57:49 +0100 Subject: [PATCH 1/2] Eliminate database calls for filed and reviewed I learned map projections and list comprehensions in cypher tonight! :tada: So much wow! --- backend/src/schema/resolvers/reports.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index fc93229ae..2b2cabd50 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -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 From fdca5b008b9f3e3eccd519e8c7925fdb87079f58 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Fri, 6 Dec 2019 02:12:47 +0100 Subject: [PATCH 2/2] Return empty array instead null for "not reviewed" @mattwr18 why did you add the null check in th resolver? --- backend/src/schema/resolvers/reports.js | 1 - .../features/ReportList/ReportList.story.js | 2 +- webapp/components/features/ReportRow/ReportRow.vue | 11 ++++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/src/schema/resolvers/reports.js b/backend/src/schema/resolvers/reports.js index 2b2cabd50..350d86d20 100644 --- a/backend/src/schema/resolvers/reports.js +++ b/backend/src/schema/resolvers/reports.js @@ -144,7 +144,6 @@ export default { }) try { const txResult = await readTxPromise - if (!txResult[0]) return null reviewed = txResult.map(reportedRecord => { const { review, moderator } = reportedRecord const relationshipWithNestedAttributes = { diff --git a/webapp/components/features/ReportList/ReportList.story.js b/webapp/components/features/ReportList/ReportList.story.js index e126f1e64..e651c4462 100644 --- a/webapp/components/features/ReportList/ReportList.story.js +++ b/webapp/components/features/ReportList/ReportList.story.js @@ -101,7 +101,7 @@ export const reports = [ slug: 'bigoted-post', title: "I'm a bigoted post!", }, - reviewed: null, + reviewed: [], }, { __typename: 'Report', diff --git a/webapp/components/features/ReportRow/ReportRow.vue b/webapp/components/features/ReportRow/ReportRow.vue index cc81ae018..6dce9c317 100644 --- a/webapp/components/features/ReportRow/ReportRow.vue +++ b/webapp/components/features/ReportRow/ReportRow.vue @@ -40,7 +40,7 @@ {{ statusText }} - +