Ulf Gebhardt 53f3a4e2e6
lint @typescript-eslint/recommended (#8406)
Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
2025-04-21 12:01:53 +02:00

48 lines
1.5 KiB
TypeScript

/* eslint-disable security/detect-object-injection */
import log from './helpers/databaseLogger'
export default {
Query: {
statistics: async (_parent, _args, { driver }) => {
const session = driver.session()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const counts: any = {}
try {
const mapping = {
countUsers: 'User',
countPosts: 'Post',
countComments: 'Comment',
countNotifications: 'NOTIFIED',
countEmails: 'EmailAddress',
countFollows: 'FOLLOWS',
countShouts: 'SHOUTED',
}
const statisticsReadTxResultPromise = session.readTransaction(async (transaction) => {
const statisticsTransactionResponse = await transaction.run(
`
CALL apoc.meta.stats() YIELD labels, relTypesCount
RETURN labels, relTypesCount
`,
)
log(statisticsTransactionResponse)
return statisticsTransactionResponse.records.map((record) => {
return {
...record.get('labels'),
...record.get('relTypesCount'),
}
})
})
const [statistics] = await statisticsReadTxResultPromise
Object.keys(mapping).forEach((key) => {
const stat = statistics[mapping[key]]
counts[key] = stat ? stat.toNumber() : 0
})
counts.countInvites = counts.countEmails - counts.countUsers
return counts
} finally {
session.close()
}
},
},
}