Skip to content

Commit

Permalink
Merge pull request desktop#19730 from desktop/cache-less
Browse files Browse the repository at this point in the history
Remove overeager caching from merge-branch-chooser
  • Loading branch information
niik authored Dec 17, 2024
2 parents 8c7782a + a0e2cd5 commit 0c9aa8c
Showing 1 changed file with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { getAheadBehind, revSymmetricDifference } from '../../../lib/git'
import { determineMergeability } from '../../../lib/git/merge-tree'
import { Branch, IAheadBehind } from '../../../models/branch'
import { Branch } from '../../../models/branch'
import { ComputedAction } from '../../../models/computed-action'
import { MergeTreeResult } from '../../../models/merge'
import { MultiCommitOperationKind } from '../../../models/multi-commit-operation'
Expand All @@ -13,19 +13,6 @@ import {
canStartOperation,
} from './base-choose-branch-dialog'
import { truncateWithEllipsis } from '../../../lib/truncate-with-ellipsis'
import QuickLRU from 'quick-lru'
import pMemoize from 'p-memoize'

const mergeTreeCache = pMemoize(determineMergeability, {
cache: new QuickLRU<string, MergeTreeResult>({ maxSize: 250 }),
cacheKey: ([_, ours, theirs]: Parameters<typeof determineMergeability>) =>
`${ours.tip.sha} <- ${theirs.tip.sha}`,
})

const aheadBehindCache = pMemoize(getAheadBehind, {
cache: new QuickLRU<string, IAheadBehind | null>({ maxSize: 250 }),
cacheKey: ([_, range]: Parameters<typeof getAheadBehind>) => range,
})

interface IMergeChooseBranchDialogState {
readonly commitCount: number
Expand Down Expand Up @@ -114,7 +101,7 @@ export class MergeChooseBranchDialog extends React.Component<
private updateStatus = async (branch: Branch) => {
const { currentBranch, repository } = this.props

const mergeStatus = await mergeTreeCache(
const mergeStatus = await determineMergeability(
repository,
currentBranch,
branch
Expand Down Expand Up @@ -142,7 +129,7 @@ export class MergeChooseBranchDialog extends React.Component<
// Commit count is used in the UI output as well as determining whether the
// submit button is enabled
const range = revSymmetricDifference('', branch.name)
const aheadBehind = await aheadBehindCache(repository, range)
const aheadBehind = await getAheadBehind(repository, range)
const commitCount = aheadBehind ? aheadBehind.behind : 0

if (this.state.selectedBranch.tip.sha !== branch.tip.sha) {
Expand Down

0 comments on commit 0c9aa8c

Please sign in to comment.