-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve branch cache logic (#17848)
Co-authored-by: Rhys Arkins <[email protected]>
- Loading branch information
1 parent
368f635
commit 72371cb
Showing
14 changed files
with
709 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
import { logger } from '../../logger'; | ||
import { getCache } from '../cache/repository'; | ||
|
||
// Compare cached parent Sha of a branch to the fetched base-branch sha to determine whether the branch is behind the base | ||
// Since cache is updated after each run, this will be sufficient to determine whether a branch is behind its parent. | ||
export function getCachedBehindBaseResult( | ||
branchName: string, | ||
currentBaseBranchSha: string | ||
branchSha: string | null, | ||
baseBranch: string, | ||
baseBranchSha: string | null | ||
): boolean | null { | ||
const cache = getCache(); | ||
const { branches = [] } = cache; | ||
const cachedBranch = branches?.find( | ||
const branch = cache.branches?.find( | ||
(branch) => branch.branchName === branchName | ||
); | ||
|
||
if (!cachedBranch?.parentSha) { | ||
return null; | ||
if ( | ||
branch && | ||
branch.sha === branchSha && | ||
branch.baseBranch === baseBranch && | ||
branch.baseBranchSha === baseBranchSha && | ||
branch.isBehindBase !== undefined | ||
) { | ||
return branch.isBehindBase; | ||
} | ||
|
||
return currentBaseBranchSha !== cachedBranch.parentSha; | ||
return null; | ||
} | ||
|
||
export function setCachedBehindBaseResult( | ||
branchName: string, | ||
isBehindBase: boolean | ||
): void { | ||
const cache = getCache(); | ||
const branch = cache.branches?.find( | ||
(branch) => branch.branchName === branchName | ||
); | ||
|
||
if (!branch) { | ||
logger.debug(`setCachedBehindBaseResult(): Branch cache not present`); | ||
return; | ||
} | ||
|
||
branch.isBehindBase = isBehindBase; | ||
} |
Oops, something went wrong.