Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b8b4b5f
Upgrade dugite to get access to new errors
May 6, 2019
f87a008
Add default messages for errors
May 6, 2019
9186e64
Add new metric
May 6, 2019
336ecce
Add error handler for new dugite error
May 6, 2019
bb897fb
Increment metric
May 6, 2019
c480510
Add metric for stashes in a repo
May 6, 2019
846b730
Add new field to repo data model
May 6, 2019
667be3d
merge old record with new
May 6, 2019
6a012e2
Add functions to get and update last stash check date
May 6, 2019
c18c15b
attempt to update stash count when branch is checked out
May 6, 2019
5f96f11
Add function that returns number of stash entries for rep
May 6, 2019
54ecb4c
Update app/package.json
outofambit May 6, 2019
175447e
Handle new error
May 6, 2019
0fa8d88
Filter out entries created by Desktop beta
May 7, 2019
2a6cc47
Try to update stash count whenever the repo is changed
May 7, 2019
4128566
Upgrade dugite
May 7, 2019
664dfdf
Rename metric
May 7, 2019
d60925d
improve test setup so they have a valid database id
shiftkey May 8, 2019
96000e3
Merge pull request #7484 from desktop/tests-need-to-use-the-databass
iAmWillShepherd May 8, 2019
4f17a6e
spreading old object can be dangerous
May 8, 2019
99ea298
Don't let errors ruin the fun
May 8, 2019
e48b89a
Update app/src/lib/stores/app-store.ts
shiftkey May 8, 2019
4ea0bd6
cache is the answer
May 8, 2019
3c6b505
We kno this is not undefined
May 8, 2019
aff4b78
Merge pull request #7488 from desktop/more-performant-baseline-stashi…
iAmWillShepherd May 8, 2019
d7ffb02
Merge branch 'releases/1.6.6' into baseline-stashing-metrics2
outofambit May 8, 2019
7ab2181
Improve error message
May 9, 2019
20b993c
Merge branch 'baseline-stashing-metrics2' of https://github.com/deskt…
May 9, 2019
88ef0ef
Update app/src/lib/git/core.ts
iAmWillShepherd May 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"deep-equal": "^1.0.1",
"dexie": "^2.0.0",
"double-ended-queue": "^2.1.0-0",
"dugite": "1.80.0",
"dugite": "1.87.0",
"electron-window-state": "^4.0.2",
"event-kit": "^2.0.0",
"file-uri-to-path": "0.0.2",
Expand Down
3 changes: 3 additions & 0 deletions app/src/lib/databases/repositories-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export interface IDatabaseRepository {
readonly gitHubRepositoryID: number | null
readonly path: string
readonly missing: boolean

/** The last time the stash entries were checked for the repository */
readonly lastStashCheckDate: number | null
}

/** The repositories database. */
Expand Down
6 changes: 6 additions & 0 deletions app/src/lib/git/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ function getDescriptionForError(error: DugiteError): string {
return 'A lock file already exists in the repository, which blocks this operation from completing.'
case DugiteError.NoMergeToAbort:
return 'There is no merge in progress, so there is nothing to abort.'
case DugiteError.NoExistingRemoteBranch:
return 'The remote branch does not exist.'
case DugiteError.LocalChangesOverwritten:
return 'Unable to switch branches as there are working directory changes which would be overwritten. Please commit or stash your changes.'
case DugiteError.UnresolvedConflicts:
return 'There are unresolved conflicts in the working directory.'
default:
return assertNever(error, `Unknown error: ${error}`)
}
Expand Down
40 changes: 40 additions & 0 deletions app/src/lib/git/stash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Repository } from '../../models/repository'
import { git } from '.'

/**
* RegEx for determining if a stash entry is created by Desktop
*
* This is done by looking for a magic string with the following
* format: `!!GitHub_Desktop<branch>`
*/
const desktopStashEntryMessageRe = /!!GitHub_Desktop<(.+)>$/

/**
* Gets the number of stash entries for the given repository
*/
export async function getStashSize(repository: Repository): Promise<number> {
const delimiter = '1F'
const format = ['%gd', '%H', '%gs'].join(`%x${delimiter}`)

const result = await git(
['log', '-g', '-z', `--pretty=${format}`, 'refs/stash'],
repository.path,
'getStashSize',
{
successExitCodes: new Set([0, 128]),
}
)

// There's no refs/stashes reflog in the repository or it's not
// even a repository. In either case we don't care
if (result.exitCode === 128) {
return 0
}

const stashEntries = result.stdout
.split('\0')
.filter(s => s !== '')
.filter(s => !desktopStashEntryMessageRe.test(s))

return stashEntries.length
}
12 changes: 12 additions & 0 deletions app/src/lib/stats/stats-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ export interface IDailyMeasures {

/** The number of times a user has pulled with `pull.rebase` unset or set to `false` */
readonly pullWithDefaultSettingCount: number

/**
* The number of stash entries created outside of Desktop
* in a given 24 hour day
*/
readonly stashEntriesCreatedOutsideDesktop: number

/**
* The number of times the user is presented with the error
* message "Some of your changes would be overwritten"
*/
readonly errorWhenSwitchingBranchesWithUncommmittedChanges: number
}

export class StatsDatabase extends Dexie {
Expand Down
25 changes: 25 additions & 0 deletions app/src/lib/stats/stats-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const DefaultDailyMeasures: IDailyMeasures = {
rebaseSuccessAfterConflictsCount: 0,
pullWithRebaseCount: 0,
pullWithDefaultSettingCount: 0,
stashEntriesCreatedOutsideDesktop: 0,
errorWhenSwitchingBranchesWithUncommmittedChanges: 0,
}

interface IOnboardingStats {
Expand Down Expand Up @@ -935,6 +937,29 @@ export class StatsStore implements IStatsStore {
}))
}

/** Record the number of stash entries created outside of Desktop for the day */
public async addStashEntriesCreatedOutsideDesktop(
stashCount: number
): Promise<void> {
return this.updateDailyMeasures(m => ({
stashEntriesCreatedOutsideDesktop:
m.stashEntriesCreatedOutsideDesktop + stashCount,
}))
}

/**
* Record the number of times the user experiences the error
* "Some of your changes would be overwritten" when switching branches
*/
public async recordErrorWhenSwitchingBranchesWithUncommmittedChanges(): Promise<
void
> {
return this.updateDailyMeasures(m => ({
errorWhenSwitchingBranchesWithUncommmittedChanges:
m.errorWhenSwitchingBranchesWithUncommmittedChanges + 1,
}))
}

private onUiActivity = async () => {
this.disableUiActivityMonitoring()

Expand Down
21 changes: 21 additions & 0 deletions app/src/lib/stores/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ import {
import { BranchPruner } from './helpers/branch-pruner'
import { enableBranchPruning, enablePullWithRebase } from '../feature-flag'
import { Banner, BannerType } from '../../models/banner'
import * as moment from 'moment'
import { getStashSize } from '../git/stash'

/**
* As fast-forwarding local branches is proportional to the number of local
Expand Down Expand Up @@ -1139,6 +1141,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
return Promise.resolve(null)
}

this.updateStashEntryCountMetric(repository)
Comment thread
shiftkey marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @iAmWillShepherd, me and @billygriffin just looked through this today in our sync-up and noticed that there's a key difference between this and what's being proposed for 1.7 (#7438) in that the 1.7 release will trigger updateStashEntryCountMetric from _refreshRepository whereas this is called from _selectRepository.

The potential problem that we see with this is for the subset of our users that have a workflow similar to my own, i.e. they work primarily in one repository (rarely switch) and they keep their desktop instances running for a long time (weeks in my case) this approach will lead to us checking and incrementing the count pretty infrequently whereas the proposed solution for 1.7 we will check once every 24 hours regardless of whether they switch or not.

The end result here could be that if the segment we're talking about isn't trivial in size (I would personally guess that it's a decent chunk of our user base) we'd see a spike in stashes created outside of desktop once we ship 1.7 which would be the opposite of what we'd want.

I would propose we amend the 1.6.6 branch with a change that moves this check to the same place as it will be in 1.7 in an effort to avoid collection inconsistencies between versions.

@iAmWillShepherd iAmWillShepherd May 14, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose we amend the 1.6.6 branch with a change that moves this check to the same place as it will be in 1.7 in an effort to avoid collection inconsistencies between versions.

I'd rather move the check in the 1.7 PR to selecectRepository. For context, the PR from 1.6.6 initially had the check in refreshRepository, but I moved it because that code path gets ran a lot and doing DB queries isn't all that fast.

I'm going to link this comment in the PR for 1.7 to make sure I make this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iAmWillShepherd It doesn't seem like you addressed @niik's feedback here.

The potential problem that we see with this is for the subset of our users that have a workflow similar to my own, i.e. they work primarily in one repository (rarely switch) and they keep their desktop instances running for a long time (weeks in my case) this approach will lead to us checking and incrementing the count pretty infrequently whereas the proposed solution for 1.7 we will check once every 24 hours regardless of whether they switch or not.

The end result here could be that if the segment we're talking about isn't trivial in size (I would personally guess that it's a decent chunk of our user base) we'd see a spike in stashes created outside of desktop once we ship 1.7 which would be the opposite of what we'd want.

setNumber(LastSelectedRepositoryIDKey, repository.id)

// if repository might be marked missing, try checking if it has been restored
Expand Down Expand Up @@ -3576,6 +3579,24 @@ export class AppStore extends TypedBaseStore<IAppState> {
this.emitUpdate()
}
}
private async updateStashEntryCountMetric(repository: Repository) {
const lastStashEntryCheck = await this.repositoriesStore.getLastStashCheckDate(
repository
)
const dateNow = moment()
const threshold = dateNow.subtract(24, 'hours')
if (lastStashEntryCheck == null || threshold.isAfter(lastStashEntryCheck)) {
// `lastStashEntryCheck` being equal to null means we've never checked for
// the given repo

try {
const stashSize = await getStashSize(repository)
this.statsStore.addStashEntriesCreatedOutsideDesktop(stashSize)
} finally {
await this.repositoriesStore.updateLastStashCheckDate(repository)
}
}
}

public _reportStats() {
// ensure the user has seen and acknowledged the current usage stats setting
Expand Down
79 changes: 78 additions & 1 deletion app/src/lib/stores/repositories-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { BaseStore } from './base-store'
export class RepositoriesStore extends BaseStore {
private db: RepositoriesDatabase

// Key-repo ID, Value-date
private lastStashCheckCache = new Map<number, number>()

public constructor(db: RepositoriesDatabase) {
super()

Expand Down Expand Up @@ -147,6 +150,7 @@ export class RepositoriesStore extends BaseStore {
path,
gitHubRepositoryID: null,
missing: false,
lastStashCheckDate: null,
})
}

Expand Down Expand Up @@ -181,11 +185,16 @@ export class RepositoriesStore extends BaseStore {
const gitHubRepositoryID = repository.gitHubRepository
? repository.gitHubRepository.dbID
: null
const oldRecord = await this.db.repositories.get(repoID)
Comment thread
iAmWillShepherd marked this conversation as resolved.
Resolved
const lastStashCheckDate =
oldRecord !== undefined ? oldRecord.lastStashCheckDate : null

await this.db.repositories.put({
id: repository.id,
path: repository.path,
missing,
gitHubRepositoryID,
lastStashCheckDate,
})

this.emitUpdate()
Expand Down Expand Up @@ -213,11 +222,16 @@ export class RepositoriesStore extends BaseStore {
const gitHubRepositoryID = repository.gitHubRepository
? repository.gitHubRepository.dbID
: null
const oldRecord = await this.db.repositories.get(repoID)
const lastStashCheckDate =
oldRecord !== undefined ? oldRecord.lastStashCheckDate : null

await this.db.repositories.put({
id: repository.id,
missing: false,
path: path,
path,
gitHubRepositoryID,
lastStashCheckDate,
})

this.emitUpdate()
Expand All @@ -230,6 +244,69 @@ export class RepositoriesStore extends BaseStore {
)
}

/**
* Sets the last time the repository was checked for stash entries
*
* @param repository The repository in which to update the last stash check date for
* @param date The date and time in which the last stash check took place; defaults to
* the current time
*/
public async updateLastStashCheckDate(
repository: Repository,
date: number = Date.now()
): Promise<void> {
const repoID = repository.id
if (repoID === 0) {
return fatalError(
'`updateLastStashCheckDate` can only update the last stash check date for a repository which has been added to the database.'
)
}

await this.db.repositories.update(repoID, {
lastStashCheckDate: date,
})

this.lastStashCheckCache.set(repoID, date)

this.emitUpdate()
}

/**
* Gets the last time the repository was checked for stash entries
*
* @param repository The repository in which to update the last stash check date for
*/
public async getLastStashCheckDate(
repository: Repository
): Promise<number | null> {
const repoID = repository.id
if (!repoID) {
return fatalError(
'`getLastStashCheckDate` - can only retrieve the last stash check date for a repositories that have been stored in the database.'
)
}

let lastCheckDate = this.lastStashCheckCache.get(repoID) || null
if (lastCheckDate !== null) {
return lastCheckDate
}

const record = await this.db.repositories.get(repoID)

if (record === undefined) {
return fatalError(
`'getLastStashCheckDate' - unable to find repository with ID: ${repoID}`
)
}

lastCheckDate = record.lastStashCheckDate
if (lastCheckDate !== null) {
this.lastStashCheckCache.set(repoID, lastCheckDate)
}

return lastCheckDate
}

private async putOwner(endpoint: string, login: string): Promise<Owner> {
login = login.toLowerCase()

Expand Down
5 changes: 5 additions & 0 deletions app/src/ui/dispatcher/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1547,4 +1547,9 @@ export class Dispatcher {
public recordRebaseConflictsDialogReopened() {
this.statsStore.recordRebaseConflictsDialogReopened()
}

/** Increments the `errorWhenSwitchingBranchesWithUncommmittedChanges` metric */
public recordErrorWhenSwitchingBranchesWithUncommmittedChanges() {
return this.statsStore.recordErrorWhenSwitchingBranchesWithUncommmittedChanges()
}
}
41 changes: 41 additions & 0 deletions app/src/ui/dispatcher/error-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,44 @@ export async function rebaseConflictsHandler(

return null
}

/**
* Handler for when we attempt to checkout a branch and there are some files that would
* be overwritten.
*/
export async function localChangesOverwrittenHandler(
error: Error,
dispatcher: Dispatcher
): Promise<Error | null> {
const e = asErrorWithMetadata(error)
if (!e) {
return error
}

const gitError = asGitError(e.underlyingError)
if (!gitError) {
return error
}

const dugiteError = gitError.result.gitError
if (!dugiteError) {
return error
}

if (dugiteError !== DugiteError.LocalChangesOverwritten) {
return error
}

const { repository } = e.metadata
if (repository == null) {
return error
}

if (!(repository instanceof Repository)) {
return error
}

dispatcher.recordErrorWhenSwitchingBranchesWithUncommmittedChanges()

return error
}
2 changes: 2 additions & 0 deletions app/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
pushNeedsPullHandler,
upstreamAlreadyExistsHandler,
rebaseConflictsHandler,
localChangesOverwrittenHandler,
} from './dispatcher'
import {
AppStore,
Expand Down Expand Up @@ -158,6 +159,7 @@ dispatcher.registerErrorHandler(gitAuthenticationErrorHandler)
dispatcher.registerErrorHandler(pushNeedsPullHandler)
dispatcher.registerErrorHandler(backgroundTaskHandler)
dispatcher.registerErrorHandler(missingRepositoryHandler)
dispatcher.registerErrorHandler(localChangesOverwrittenHandler)

if (enablePullWithRebase()) {
dispatcher.registerErrorHandler(rebaseConflictsHandler)
Expand Down
Loading