From 65d45d7e82d4148b5157f634111aa7bb07d06b68 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 10 Oct 2024 21:13:04 +0700 Subject: [PATCH] Few github high cpu load fixes (#6865) Signed-off-by: Andrey Sobolev --- services/github/pod-github/src/sync/issueBase.ts | 15 +++++++++++---- .../github/pod-github/src/sync/pullrequests.ts | 4 ++++ .../github/pod-github/src/sync/repository.ts | 16 +++++++++------- services/github/pod-github/src/worker.ts | 3 --- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/services/github/pod-github/src/sync/issueBase.ts b/services/github/pod-github/src/sync/issueBase.ts index 73f49cf34d..f2e9c9278a 100644 --- a/services/github/pod-github/src/sync/issueBase.ts +++ b/services/github/pod-github/src/sync/issueBase.ts @@ -628,9 +628,17 @@ export abstract class IssueSyncManagerBase { itemId: target.prjData?.id as string }) } catch (err: any) { + if (err.errors?.[0]?.type === 'NOT_FOUND') { + errors.push({ error: err, response }) + return errors + } Analytics.handleError(err) // 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 }) } } @@ -892,10 +900,9 @@ export abstract class IssueSyncManagerBase { } if (fieldsUpdate.length > 0 && syncToProject && target.prjData !== undefined) { const errors = await this.updateIssueValues(target, okit, fieldsUpdate) - if (errors.length > 0) { - return { externalVersion: '', needUpdate: githubSyncVersion, error: errors } + if (errors.length === 0) { + needExternalSync = true } - needExternalSync = true } // TODO: Add support for labels, milestone, assignees } diff --git a/services/github/pod-github/src/sync/pullrequests.ts b/services/github/pod-github/src/sync/pullrequests.ts index b8885f5809..8ef9fd275d 100644 --- a/services/github/pod-github/src/sync/pullrequests.ts +++ b/services/github/pod-github/src/sync/pullrequests.ts @@ -971,6 +971,10 @@ export class PullRequestSyncManager extends IssueSyncManagerBase implements DocS return { needSync: githubSyncVersion } } + if (info.repository == null) { + return { needSync: githubSyncVersion } + } + const pullRequestExternal = info.external as unknown as PullRequestExternalData if (info.externalVersion !== githubExternalSyncVersion) { diff --git a/services/github/pod-github/src/sync/repository.ts b/services/github/pod-github/src/sync/repository.ts index bafaf1d542..998cd08006 100644 --- a/services/github/pod-github/src/sync/repository.ts +++ b/services/github/pod-github/src/sync/repository.ts @@ -265,7 +265,14 @@ export class RepositorySyncMapper implements DocSyncManager { let allRepos: GithubIntegrationRepository[] = [...allRepositories] + const githubRepos: + | Repository + | Endpoints['GET /installation/repositories']['response']['data']['repositories'][0][] = [] for await (const { repository } of iterable) { + githubRepos.push(repository) + } + + for (const repository of githubRepos) { const integrationRepo: GithubIntegrationRepository | undefined = allRepos.find( (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. for (const repo of allRepos) { - await this.client.remove(repo) - const prj = projects.find((it) => it._id === repo.githubProject) - if (prj !== undefined) { - await this.client.update(prj, { - $pull: { repositories: repo._id } - }) - } + // Mark as archived + await this.client.update(repo, { archived: true }) } // We need to delete and disconnect missing repositories. diff --git a/services/github/pod-github/src/worker.ts b/services/github/pod-github/src/worker.ts index 473822d6bd..db5f974876 100644 --- a/services/github/pod-github/src/worker.ts +++ b/services/github/pod-github/src/worker.ts @@ -395,9 +395,6 @@ export class GithubWorker implements IntegrationManager { periodicSyncPromise: Promise | undefined async performPeriodicSync (): Promise { try { - for (const inst of this.integrations.values()) { - await this.repositoryManager.reloadRepositories(inst) - } this.triggerUpdate() } catch (err: any) { Analytics.handleError(err)