Skip to content

Commit 3c19703

Browse files
committed
fix(backend): only sync required branches
In the recurring Sync Git Repositories task, only sync branches that are flagged with the sync_with_git flag. Signed-off-by: Fatih Acar <fatih@opsmill.com>
1 parent 4d9ffda commit 3c19703

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

backend/infrahub/git/tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ async def sync_remote_repositories() -> None:
201201

202202
branches = await client.branch.all()
203203
async with db.start_session() as dbs:
204-
repositories = await get_repositories_commit_per_branch(db=dbs, kind=InfrahubKind.REPOSITORY)
204+
repositories = await get_repositories_commit_per_branch(
205+
db=dbs, kind=InfrahubKind.REPOSITORY, only_sync_with_git=True
206+
)
205207

206208
for repo_name, repository_data in repositories.items():
207209
repository: CoreRepository = repository_data.repository

backend/infrahub/git/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
async def get_repositories_commit_per_branch(
2626
db: InfrahubDatabase,
2727
kind: str = InfrahubKind.GENERICREPOSITORY,
28+
only_sync_with_git: bool = False,
2829
) -> dict[str, RepositoryData]:
2930
"""Get a list of all repositories and their commit on each branches.
3031
@@ -36,6 +37,9 @@ async def get_repositories_commit_per_branch(
3637
repositories: dict[str, RepositoryData] = {}
3738

3839
for branch in list(registry.branch.values()):
40+
if only_sync_with_git and not branch.sync_with_git:
41+
continue
42+
3943
repos: list[CoreRepository | CoreReadOnlyRepository] = await NodeManager.query(
4044
db=db,
4145
branch=branch,

0 commit comments

Comments
 (0)