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": "*",
|
"core": "*",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"database": "*",
|
"database": "*",
|
||||||
"dataloader": "^2.2.3",
|
|
||||||
"decimal.js-light": "^2.5.1",
|
"decimal.js-light": "^2.5.1",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"esbuild": "^0.25.2",
|
"esbuild": "^0.25.2",
|
||||||
|
|||||||
@ -27,7 +27,6 @@ import {
|
|||||||
getLastTransaction,
|
getLastTransaction,
|
||||||
UserContact,
|
UserContact,
|
||||||
} from 'database'
|
} from 'database'
|
||||||
import DataLoader from 'dataloader'
|
|
||||||
import { Decimal } from 'decimal.js-light'
|
import { Decimal } from 'decimal.js-light'
|
||||||
import { GraphQLResolveInfo } from 'graphql'
|
import { GraphQLResolveInfo } from 'graphql'
|
||||||
import { getLogger } from 'log4js'
|
import { getLogger } from 'log4js'
|
||||||
@ -375,28 +374,32 @@ export class ContributionResolver {
|
|||||||
)
|
)
|
||||||
const result = new ContributionListResult(count, dbContributions)
|
const result = new ContributionListResult(count, dbContributions)
|
||||||
|
|
||||||
const dataLoader = new DataLoader(async (userIds: readonly number[]) => {
|
const uniqueUserIds = new Set<number>()
|
||||||
const uniqueUserIds = new Set<number>()
|
const addIfExist = (userId?: number | null) => {
|
||||||
userIds.forEach((userId) => uniqueUserIds.add(userId))
|
if (userId) {
|
||||||
const users = await findUserNamesByIds(Array.from(uniqueUserIds))
|
uniqueUserIds.add(userId)
|
||||||
return userIds.map((userId) => users.get(userId))
|
}
|
||||||
})
|
}
|
||||||
|
const getNameById = (userId?: number | null) => {
|
||||||
|
if (userId) {
|
||||||
|
return users.get(userId)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
for (const contribution of result.contributionList) {
|
for (const contribution of result.contributionList) {
|
||||||
if (contribution.confirmedBy) {
|
addIfExist(contribution.confirmedBy)
|
||||||
contribution.confirmedByUserName = await dataLoader.load(contribution.confirmedBy)
|
addIfExist(contribution.updatedBy)
|
||||||
}
|
addIfExist(contribution.moderatorId)
|
||||||
if (contribution.updatedBy) {
|
addIfExist(contribution.deletedBy)
|
||||||
contribution.updatedByUserName = await dataLoader.load(contribution.updatedBy)
|
addIfExist(contribution.deniedBy)
|
||||||
}
|
}
|
||||||
if (contribution.moderatorId) {
|
const users = await findUserNamesByIds(Array.from(uniqueUserIds))
|
||||||
contribution.moderatorUserName = await dataLoader.load(contribution.moderatorId)
|
for (const contribution of result.contributionList) {
|
||||||
}
|
contribution.confirmedByUserName = getNameById(contribution.confirmedBy)
|
||||||
if (contribution.deletedBy) {
|
contribution.updatedByUserName = getNameById(contribution.updatedBy)
|
||||||
contribution.deletedByUserName = await dataLoader.load(contribution.deletedBy)
|
contribution.moderatorUserName = getNameById(contribution.moderatorId)
|
||||||
}
|
contribution.deletedByUserName = getNameById(contribution.deletedBy)
|
||||||
if (contribution.deniedBy) {
|
contribution.deniedByUserName = getNameById(contribution.deniedBy)
|
||||||
contribution.deniedByUserName = await dataLoader.load(contribution.deniedBy)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
3
bun.lock
3
bun.lock
@ -122,7 +122,6 @@
|
|||||||
"core": "*",
|
"core": "*",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"database": "*",
|
"database": "*",
|
||||||
"dataloader": "^2.2.3",
|
|
||||||
"decimal.js-light": "^2.5.1",
|
"decimal.js-light": "^2.5.1",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"esbuild": "^0.25.2",
|
"esbuild": "^0.25.2",
|
||||||
@ -1809,8 +1808,6 @@
|
|||||||
|
|
||||||
"database": ["database@workspace:database"],
|
"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-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=="],
|
"date-format": ["date-format@4.0.14", "", {}, "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg=="],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user