Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve Network Graph end-point #305

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/services/memberActivity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ type memberInteractionType = { id: string, radius: number, stats: NodeStats } &
type memberInteractionsGraphResponseType = { width: number, from: memberInteractionType, to: memberInteractionType }[]
async function getMembersInteractionsNetworkGraph(guildId: string, guildConnection: Connection): Promise<memberInteractionsGraphResponseType> {
// TODO: refactor function later
const usersInNetworkGraph: string[] = []
// userInteraction
const usersInteractionsQuery = `
MATCH () -[r:INTERACTED_WITH {guildId: "${guildId}"}]-()
Expand All @@ -919,6 +920,8 @@ async function getMembersInteractionsNetworkGraph(guildId: string, guildConnecti
const rWeeklyInteraction = r?.properties?.weight as number
const bUserId = b?.properties?.userId as string

usersInNetworkGraph.push(aUserId)
usersInNetworkGraph.push(bUserId)
const interaction = {
aUserId,
bUserId,
Expand Down Expand Up @@ -967,8 +970,9 @@ async function getMembersInteractionsNetworkGraph(guildId: string, guildConnecti
})

// usersInfo
const usersInfo = await guildConnection.models.GuildMember.find()
const roles = await roleService.getRoles(guildConnection, {})
const usersInfo = await guildConnection.models.GuildMember.find({ discordIds: { $in: usersInNetworkGraph } });
const rolesInNetworkGraph = usersInfo.flatMap((user) => user.roles)
const roles = await roleService.getRoles(guildConnection, { roleId: { $in: rolesInNetworkGraph } })

// prepare data
const response = usersInteractions.flatMap((interaction) => {
Expand Down