Skip to content
Merged
Show file tree
Hide file tree
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
97 changes: 46 additions & 51 deletions backend/src/database/repositories/integrationProgressRepository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { QueryTypes } from 'sequelize'

import { queryActivitiesCounter } from '@crowd/data-access-layer'
import { Counter, TinybirdClient } from '@crowd/data-access-layer/src/database'

import { Repos } from '@/serverless/integrations/types/regularTypes'
import { GitHubStats } from '@/serverless/integrations/usecases/github/rest/getRemoteStats'

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

static async getDbStatsForGithub({
repos,
segments,
}: {
repos: Repos
segments: string[]
}): Promise<GitHubStats> {
const tb = new TinybirdClient()

const promises: Promise<{ data: Counter }>[] = [
queryActivitiesCounter(
IntegrationProgressRepository.createPayloadWithActivityType(['star'], repos, segments),
tb,
),
queryActivitiesCounter(
IntegrationProgressRepository.createPayloadWithActivityType(['unstar'], repos, segments),
tb,
),
queryActivitiesCounter(
{
...IntegrationProgressRepository.createPayloadWithActivityType(['fork'], repos, segments),
indirectFork: 1,
},
tb,
),
queryActivitiesCounter(
IntegrationProgressRepository.createPayloadWithActivityType(
['issues-opened'],
repos,
segments,
),
tb,
),
queryActivitiesCounter(
IntegrationProgressRepository.createPayloadWithActivityType(
['pull_request-opened'],
repos,
segments,
),
tb,
),
]

const result = await Promise.all(promises)
static async getDbStatsForGithub(): Promise<GitHubStats> {
// const tb = new TinybirdClient()

// const promises: Promise<{ data: Counter }>[] = [
// queryActivitiesCounter(
// IntegrationProgressRepository.createPayloadWithActivityType(['star'], repos, segments),
// tb,
// ),
// queryActivitiesCounter(
// IntegrationProgressRepository.createPayloadWithActivityType(['unstar'], repos, segments),
// tb,
// ),
// queryActivitiesCounter(
// {
// ...IntegrationProgressRepository.createPayloadWithActivityType(['fork'], repos, segments),
// indirectFork: 1,
// },
// tb,
// ),
// queryActivitiesCounter(
// IntegrationProgressRepository.createPayloadWithActivityType(
// ['issues-opened'],
// repos,
// segments,
// ),
// tb,
// ),
// queryActivitiesCounter(
// IntegrationProgressRepository.createPayloadWithActivityType(
// ['pull_request-opened'],
// repos,
// segments,
// ),
// tb,
// ),
// ]

// const result = await Promise.all(promises)

return {
stars: (result[0]?.data?.[0]?.count ?? 0) - (result[1]?.data?.[0]?.count ?? 0),
forks: result[2]?.data?.[0]?.count ?? 0,
totalIssues: result[3]?.data?.[0]?.count ?? 0,
totalPRs: result[4]?.data?.[0]?.count ?? 0,
// stars: (result[0]?.data?.[0]?.count ?? 0) - (result[1]?.data?.[0]?.count ?? 0),
// forks: result[2]?.data?.[0]?.count ?? 0,
// totalIssues: result[3]?.data?.[0]?.count ?? 0,
// totalPRs: result[4]?.data?.[0]?.count ?? 0,
stars: 0,
forks: 0,
totalIssues: 0,
totalPRs: 0,
}
}

Expand Down
6 changes: 1 addition & 5 deletions backend/src/services/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2195,16 +2195,12 @@ export default class IntegrationService {
this.options.log.debug(
`Evaluating cache for repos: ${repos.map((r) => r.name).join(',')} and segments: ${segments}`,
)
cachedStats = await IntegrationProgressRepository.getDbStatsForGithub({
repos,
segments,
})
cachedStats = await IntegrationProgressRepository.getDbStatsForGithub()

this.options.log.debug(`Caching data: ${JSON.stringify(cachedStats)}`)
// cache for 1 minute
await cacheDb.set(key, JSON.stringify(cachedStats), 60)
} else {
this.options.log.debug(`Cache data found: ${JSON.stringify(cachedStats)}`)
cachedStats = JSON.parse(cachedStats)
}
return cachedStats as GitHubStats
Expand Down
Loading