Skip to content

Commit

Permalink
Merge pull request #305 from TogetherCrew/feature/network-graph-impro…
Browse files Browse the repository at this point in the history
…vement

fix: improve Network Graph end-point
  • Loading branch information
cyri113 authored Feb 13, 2024
2 parents e489406 + cd506c5 commit d2efce1
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit d2efce1

Please sign in to comment.