Few github high cpu load fixes (#6865)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-10-10 21:13:04 +07:00 committed by GitHub
parent dd8a9a0d85
commit 65d45d7e82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 14 deletions

View File

@ -628,9 +628,17 @@ export abstract class IssueSyncManagerBase {
itemId: target.prjData?.id as string itemId: target.prjData?.id as string
}) })
} catch (err: any) { } catch (err: any) {
if (err.errors?.[0]?.type === 'NOT_FOUND') {
errors.push({ error: err, response })
return errors
}
Analytics.handleError(err) Analytics.handleError(err)
// Failed to update one particular value, skip it. // Failed to update one particular value, skip it.
this.ctx.error('error during field update', { error: err, response }) this.ctx.error('error during field update', {
error: err,
response,
workspace: this.provider.getWorkspaceId().name
})
errors.push({ error: err, response }) errors.push({ error: err, response })
} }
} }
@ -892,10 +900,9 @@ export abstract class IssueSyncManagerBase {
} }
if (fieldsUpdate.length > 0 && syncToProject && target.prjData !== undefined) { if (fieldsUpdate.length > 0 && syncToProject && target.prjData !== undefined) {
const errors = await this.updateIssueValues(target, okit, fieldsUpdate) const errors = await this.updateIssueValues(target, okit, fieldsUpdate)
if (errors.length > 0) { if (errors.length === 0) {
return { externalVersion: '', needUpdate: githubSyncVersion, error: errors } needExternalSync = true
} }
needExternalSync = true
} }
// TODO: Add support for labels, milestone, assignees // TODO: Add support for labels, milestone, assignees
} }

View File

@ -971,6 +971,10 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS
return { needSync: githubSyncVersion } return { needSync: githubSyncVersion }
} }
if (info.repository == null) {
return { needSync: githubSyncVersion }
}
const pullRequestExternal = info.external as unknown as PullRequestExternalData const pullRequestExternal = info.external as unknown as PullRequestExternalData
if (info.externalVersion !== githubExternalSyncVersion) { if (info.externalVersion !== githubExternalSyncVersion) {

View File

@ -265,7 +265,14 @@ export class RepositorySyncMapper implements DocSyncManager {
let allRepos: GithubIntegrationRepository[] = [...allRepositories] let allRepos: GithubIntegrationRepository[] = [...allRepositories]
const githubRepos:
| Repository
| Endpoints['GET /installation/repositories']['response']['data']['repositories'][0][] = []
for await (const { repository } of iterable) { for await (const { repository } of iterable) {
githubRepos.push(repository)
}
for (const repository of githubRepos) {
const integrationRepo: GithubIntegrationRepository | undefined = allRepos.find( const integrationRepo: GithubIntegrationRepository | undefined = allRepos.find(
(it) => it.repositoryId === repository.id (it) => it.repositoryId === repository.id
) )
@ -325,13 +332,8 @@ export class RepositorySyncMapper implements DocSyncManager {
// Ok we have repos removed from integration, we need to delete them. // Ok we have repos removed from integration, we need to delete them.
for (const repo of allRepos) { for (const repo of allRepos) {
await this.client.remove(repo) // Mark as archived
const prj = projects.find((it) => it._id === repo.githubProject) await this.client.update(repo, { archived: true })
if (prj !== undefined) {
await this.client.update(prj, {
$pull: { repositories: repo._id }
})
}
} }
// We need to delete and disconnect missing repositories. // We need to delete and disconnect missing repositories.

View File

@ -395,9 +395,6 @@ export class GithubWorker implements IntegrationManager {
periodicSyncPromise: Promise<void> | undefined periodicSyncPromise: Promise<void> | undefined
async performPeriodicSync (): Promise<void> { async performPeriodicSync (): Promise<void> {
try { try {
for (const inst of this.integrations.values()) {
await this.repositoryManager.reloadRepositories(inst)
}
this.triggerUpdate() this.triggerUpdate()
} catch (err: any) { } catch (err: any) {
Analytics.handleError(err) Analytics.handleError(err)