Skip to content

Commit a229645

Browse files
committed
fix(sidebar): ignore stash metrics for synthetic worktree rows
1 parent eb89318 commit a229645

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

app/src/lib/stores/repositories-store.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ export class RepositoriesStore extends TypedBaseStore<
479479
repository: Repository,
480480
date: number = Date.now()
481481
): Promise<void> {
482+
// Synthetic sidebar-only worktree rows are transient repositories that
483+
// are not persisted in the repositories store.
484+
if (repository.id < 0) {
485+
return
486+
}
487+
482488
await this.db.repositories.update(repository.id, {
483489
lastStashCheckDate: date,
484490
})
@@ -496,6 +502,12 @@ export class RepositoriesStore extends TypedBaseStore<
496502
public async getLastStashCheckDate(
497503
repository: Repository
498504
): Promise<number | null> {
505+
// Synthetic sidebar-only worktree rows are transient repositories that
506+
// are not persisted in the repositories store.
507+
if (repository.id < 0) {
508+
return null
509+
}
510+
499511
let lastCheckDate = this.lastStashCheckCache.get(repository.id) || null
500512
if (lastCheckDate !== null) {
501513
return lastCheckDate

app/test/unit/repositories-store-test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import assert from 'node:assert'
33
import { RepositoriesStore } from '../../src/lib/stores/repositories-store'
44
import { TestRepositoriesDatabase } from '../helpers/databases'
55
import { IAPIFullRepository, getDotComAPIEndpoint } from '../../src/lib/api'
6-
import { assertIsRepositoryWithGitHubRepository } from '../../src/models/repository'
6+
import {
7+
assertIsRepositoryWithGitHubRepository,
8+
Repository,
9+
} from '../../src/models/repository'
10+
import { gitHubRepoFixture } from '../helpers/github-repo-builder'
711

812
describe('RepositoriesStore', () => {
913
let repoDb = new TestRepositoriesDatabase()
@@ -97,4 +101,22 @@ describe('RepositoriesStore', () => {
97101
)
98102
})
99103
})
104+
105+
describe('stash check tracking', () => {
106+
it('ignores transient synthetic repositories', async () => {
107+
const syntheticRepo = new Repository(
108+
'/tmp/repo-feature-a',
109+
-1,
110+
gitHubRepoFixture({ owner: 'example', name: 'repo' }),
111+
false
112+
)
113+
114+
assert.equal(
115+
await repositoriesStore.getLastStashCheckDate(syntheticRepo),
116+
null
117+
)
118+
119+
await repositoriesStore.updateLastStashCheckDate(syntheticRepo)
120+
})
121+
})
100122
})

0 commit comments

Comments
 (0)