Skip to content

Commit a450352

Browse files
authored
fix: remove heavy query [CM-701] (#3506)
1 parent c3f02db commit a450352

2 files changed

Lines changed: 47 additions & 56 deletions

File tree

backend/src/database/repositories/integrationProgressRepository.ts

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { QueryTypes } from 'sequelize'
22

3-
import { queryActivitiesCounter } from '@crowd/data-access-layer'
4-
import { Counter, TinybirdClient } from '@crowd/data-access-layer/src/database'
5-
63
import { Repos } from '@/serverless/integrations/types/regularTypes'
74
import { GitHubStats } from '@/serverless/integrations/usecases/github/rest/getRemoteStats'
85

@@ -86,56 +83,54 @@ class IntegrationProgressRepository {
8683
return (result[0] as any).id as string
8784
}
8885

89-
static async getDbStatsForGithub({
90-
repos,
91-
segments,
92-
}: {
93-
repos: Repos
94-
segments: string[]
95-
}): Promise<GitHubStats> {
96-
const tb = new TinybirdClient()
97-
98-
const promises: Promise<{ data: Counter }>[] = [
99-
queryActivitiesCounter(
100-
IntegrationProgressRepository.createPayloadWithActivityType(['star'], repos, segments),
101-
tb,
102-
),
103-
queryActivitiesCounter(
104-
IntegrationProgressRepository.createPayloadWithActivityType(['unstar'], repos, segments),
105-
tb,
106-
),
107-
queryActivitiesCounter(
108-
{
109-
...IntegrationProgressRepository.createPayloadWithActivityType(['fork'], repos, segments),
110-
indirectFork: 1,
111-
},
112-
tb,
113-
),
114-
queryActivitiesCounter(
115-
IntegrationProgressRepository.createPayloadWithActivityType(
116-
['issues-opened'],
117-
repos,
118-
segments,
119-
),
120-
tb,
121-
),
122-
queryActivitiesCounter(
123-
IntegrationProgressRepository.createPayloadWithActivityType(
124-
['pull_request-opened'],
125-
repos,
126-
segments,
127-
),
128-
tb,
129-
),
130-
]
131-
132-
const result = await Promise.all(promises)
86+
static async getDbStatsForGithub(): Promise<GitHubStats> {
87+
// const tb = new TinybirdClient()
88+
89+
// const promises: Promise<{ data: Counter }>[] = [
90+
// queryActivitiesCounter(
91+
// IntegrationProgressRepository.createPayloadWithActivityType(['star'], repos, segments),
92+
// tb,
93+
// ),
94+
// queryActivitiesCounter(
95+
// IntegrationProgressRepository.createPayloadWithActivityType(['unstar'], repos, segments),
96+
// tb,
97+
// ),
98+
// queryActivitiesCounter(
99+
// {
100+
// ...IntegrationProgressRepository.createPayloadWithActivityType(['fork'], repos, segments),
101+
// indirectFork: 1,
102+
// },
103+
// tb,
104+
// ),
105+
// queryActivitiesCounter(
106+
// IntegrationProgressRepository.createPayloadWithActivityType(
107+
// ['issues-opened'],
108+
// repos,
109+
// segments,
110+
// ),
111+
// tb,
112+
// ),
113+
// queryActivitiesCounter(
114+
// IntegrationProgressRepository.createPayloadWithActivityType(
115+
// ['pull_request-opened'],
116+
// repos,
117+
// segments,
118+
// ),
119+
// tb,
120+
// ),
121+
// ]
122+
123+
// const result = await Promise.all(promises)
133124

134125
return {
135-
stars: (result[0]?.data?.[0]?.count ?? 0) - (result[1]?.data?.[0]?.count ?? 0),
136-
forks: result[2]?.data?.[0]?.count ?? 0,
137-
totalIssues: result[3]?.data?.[0]?.count ?? 0,
138-
totalPRs: result[4]?.data?.[0]?.count ?? 0,
126+
// stars: (result[0]?.data?.[0]?.count ?? 0) - (result[1]?.data?.[0]?.count ?? 0),
127+
// forks: result[2]?.data?.[0]?.count ?? 0,
128+
// totalIssues: result[3]?.data?.[0]?.count ?? 0,
129+
// totalPRs: result[4]?.data?.[0]?.count ?? 0,
130+
stars: 0,
131+
forks: 0,
132+
totalIssues: 0,
133+
totalPRs: 0,
139134
}
140135
}
141136

backend/src/services/integrationService.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,16 +2195,12 @@ export default class IntegrationService {
21952195
this.options.log.debug(
21962196
`Evaluating cache for repos: ${repos.map((r) => r.name).join(',')} and segments: ${segments}`,
21972197
)
2198-
cachedStats = await IntegrationProgressRepository.getDbStatsForGithub({
2199-
repos,
2200-
segments,
2201-
})
2198+
cachedStats = await IntegrationProgressRepository.getDbStatsForGithub()
22022199

22032200
this.options.log.debug(`Caching data: ${JSON.stringify(cachedStats)}`)
22042201
// cache for 1 minute
22052202
await cacheDb.set(key, JSON.stringify(cachedStats), 60)
22062203
} else {
2207-
this.options.log.debug(`Cache data found: ${JSON.stringify(cachedStats)}`)
22082204
cachedStats = JSON.parse(cachedStats)
22092205
}
22102206
return cachedStats as GitHubStats

0 commit comments

Comments
 (0)