Merge pull request #2435 from Human-Connection/eliminate_database_calls

Eliminate database calls for reports query
This commit is contained in:
mattwr18 2019-12-06 10:36:50 +01:00 committed by GitHub
commit 3a455a647a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

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
@ -141,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 = {

View File

@ -101,7 +101,7 @@ export const reports = [
slug: 'bigoted-post',
title: "I'm a bigoted post!",
},
reviewed: null,
reviewed: [],
},
{
__typename: 'Report',

View File

@ -40,7 +40,7 @@
<base-icon :name="statusIconName" :class="isDisabled ? '--disabled' : '--enabled'" />
{{ statusText }}
</span>
<client-only v-if="report.reviewed">
<client-only v-if="isReviewed">
<hc-user
:user="moderatorOfLatestReview"
:showAvatar="false"
@ -109,6 +109,10 @@ export default {
isDisabled() {
return this.report.resource.disabled
},
isReviewed() {
const { reviewed } = this.report
return reviewed && reviewed.length
},
iconName() {
if (this.isPost) return 'bookmark'
else if (this.isComment) return 'comments'
@ -138,12 +142,13 @@ export default {
return this.isDisabled ? 'eye-slash' : 'eye'
},
statusText() {
if (!this.report.reviewed) return this.$t('moderation.reports.enabled')
if (!this.isReviewed) return this.$t('moderation.reports.enabled')
else if (this.isDisabled) return this.$t('moderation.reports.disabledBy')
else return this.$t('moderation.reports.enabledBy')
},
moderatorOfLatestReview() {
return this.report.reviewed[0].moderator
const [latestReview] = this.report.reviewed
return latestReview && latestReview.moderator
},
},
}