From 4ba8773d8ba5797372dcc53af1d2d2cc718dc0cf Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Fri, 2 Feb 2024 11:41:05 +0400 Subject: [PATCH 1/2] fix: improve getworkGraph end-point more improvements are possible --- src/services/memberActivity.service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/memberActivity.service.ts b/src/services/memberActivity.service.ts index c5da1ba4..d1062d16 100644 --- a/src/services/memberActivity.service.ts +++ b/src/services/memberActivity.service.ts @@ -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 { // TODO: refactor function later + const usersInNetworkGraph: string[] = [] // userInteraction const usersInteractionsQuery = ` MATCH () -[r:INTERACTED_WITH {guildId: "${guildId}"}]-() @@ -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, @@ -967,7 +970,7 @@ async function getMembersInteractionsNetworkGraph(guildId: string, guildConnecti }) // usersInfo - const usersInfo = await guildConnection.models.GuildMember.find() + const usersInfo = await guildConnection.models.GuildMember.find({ discordIds: { $in: usersInNetworkGraph } }); const roles = await roleService.getRoles(guildConnection, {}) // prepare data From cd506c531f7c638ee1fa0e1c590960d5c825b27a Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Fri, 2 Feb 2024 12:02:53 +0400 Subject: [PATCH 2/2] feat: a new update on network graph --- src/services/memberActivity.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/memberActivity.service.ts b/src/services/memberActivity.service.ts index d1062d16..7aba4199 100644 --- a/src/services/memberActivity.service.ts +++ b/src/services/memberActivity.service.ts @@ -971,7 +971,8 @@ async function getMembersInteractionsNetworkGraph(guildId: string, guildConnecti // usersInfo const usersInfo = await guildConnection.models.GuildMember.find({ discordIds: { $in: usersInNetworkGraph } }); - const roles = await roleService.getRoles(guildConnection, {}) + const rolesInNetworkGraph = usersInfo.flatMap((user) => user.roles) + const roles = await roleService.getRoles(guildConnection, { roleId: { $in: rolesInNetworkGraph } }) // prepare data const response = usersInteractions.flatMap((interaction) => {