mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
retrieve user names without using slow dataloader
This commit is contained in:
parent
c3acd21a67
commit
31a6b28c85
@ -60,7 +60,6 @@
|
||||
"core": "*",
|
||||
"cors": "^2.8.5",
|
||||
"database": "*",
|
||||
"dataloader": "^2.2.3",
|
||||
"decimal.js-light": "^2.5.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"esbuild": "^0.25.2",
|
||||
|
||||
@ -27,7 +27,6 @@ import {
|
||||
getLastTransaction,
|
||||
UserContact,
|
||||
} from 'database'
|
||||
import DataLoader from 'dataloader'
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import { GraphQLResolveInfo } from 'graphql'
|
||||
import { getLogger } from 'log4js'
|
||||
@ -375,28 +374,32 @@ export class ContributionResolver {
|
||||
)
|
||||
const result = new ContributionListResult(count, dbContributions)
|
||||
|
||||
const dataLoader = new DataLoader(async (userIds: readonly number[]) => {
|
||||
const uniqueUserIds = new Set<number>()
|
||||
userIds.forEach((userId) => uniqueUserIds.add(userId))
|
||||
const users = await findUserNamesByIds(Array.from(uniqueUserIds))
|
||||
return userIds.map((userId) => users.get(userId))
|
||||
})
|
||||
const uniqueUserIds = new Set<number>()
|
||||
const addIfExist = (userId?: number | null) => {
|
||||
if (userId) {
|
||||
uniqueUserIds.add(userId)
|
||||
}
|
||||
}
|
||||
const getNameById = (userId?: number | null) => {
|
||||
if (userId) {
|
||||
return users.get(userId)
|
||||
}
|
||||
return null
|
||||
}
|
||||
for (const contribution of result.contributionList) {
|
||||
if (contribution.confirmedBy) {
|
||||
contribution.confirmedByUserName = await dataLoader.load(contribution.confirmedBy)
|
||||
}
|
||||
if (contribution.updatedBy) {
|
||||
contribution.updatedByUserName = await dataLoader.load(contribution.updatedBy)
|
||||
}
|
||||
if (contribution.moderatorId) {
|
||||
contribution.moderatorUserName = await dataLoader.load(contribution.moderatorId)
|
||||
}
|
||||
if (contribution.deletedBy) {
|
||||
contribution.deletedByUserName = await dataLoader.load(contribution.deletedBy)
|
||||
}
|
||||
if (contribution.deniedBy) {
|
||||
contribution.deniedByUserName = await dataLoader.load(contribution.deniedBy)
|
||||
}
|
||||
addIfExist(contribution.confirmedBy)
|
||||
addIfExist(contribution.updatedBy)
|
||||
addIfExist(contribution.moderatorId)
|
||||
addIfExist(contribution.deletedBy)
|
||||
addIfExist(contribution.deniedBy)
|
||||
}
|
||||
const users = await findUserNamesByIds(Array.from(uniqueUserIds))
|
||||
for (const contribution of result.contributionList) {
|
||||
contribution.confirmedByUserName = getNameById(contribution.confirmedBy)
|
||||
contribution.updatedByUserName = getNameById(contribution.updatedBy)
|
||||
contribution.moderatorUserName = getNameById(contribution.moderatorId)
|
||||
contribution.deletedByUserName = getNameById(contribution.deletedBy)
|
||||
contribution.deniedByUserName = getNameById(contribution.deniedBy)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
3
bun.lock
3
bun.lock
@ -122,7 +122,6 @@
|
||||
"core": "*",
|
||||
"cors": "^2.8.5",
|
||||
"database": "*",
|
||||
"dataloader": "^2.2.3",
|
||||
"decimal.js-light": "^2.5.1",
|
||||
"dotenv": "^10.0.0",
|
||||
"esbuild": "^0.25.2",
|
||||
@ -1809,8 +1808,6 @@
|
||||
|
||||
"database": ["database@workspace:database"],
|
||||
|
||||
"dataloader": ["dataloader@2.2.3", "", {}, "sha512-y2krtASINtPFS1rSDjacrFgn1dcUuoREVabwlOGOe4SdxenREqwjwjElAdwvbGM7kgZz9a3KVicWR7vcz8rnzA=="],
|
||||
|
||||
"date-fns": ["date-fns@2.30.0", "", { "dependencies": { "@babel/runtime": "^7.21.0" } }, "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw=="],
|
||||
|
||||
"date-format": ["date-format@4.0.14", "", {}, "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg=="],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user