Skip to content

Check API for updates before fetching - #5320

Merged
shiftkey merged 28 commits into
masterfrom
check-before-fetch
Aug 9, 2018
Merged

shiftkey merged 28 commits into
masterfrom
check-before-fetch

Conversation

@iAmWillShepherd

@iAmWillShepherd iAmWillShepherd commented Aug 2, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #5312

Related discussion: #1252

Comment thread app/src/lib/stores/app-store.ts Outdated
return
}

const account = getAccountForRepository(this.accounts, repository)

This comment was marked as spam.

@shiftkey shiftkey left a comment

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.

I like where this is heading, but before I go and try and break this code here's some initial feedback

Comment thread app/src/lib/stores/app-store.ts Outdated

return true
// we should fetch if the last push happened after the last fetch
const shouldFetch = lastPush !== undefined ? lastFetched < lastPush : true

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated
let lastPush: Date | undefined
const account = getAccountForRepository(this.accounts, repository)
if (account !== null && repository.gitHubRepository) {
// NOTE: does this look at if your current branch is tracking a different remote

This comment was marked as spam.

@desktop desktop deleted a comment from parvaizmuhd Aug 2, 2018
@iAmWillShepherd

Copy link
Copy Markdown
Contributor Author

💯

Tested with my local repos.

Note, I had to modify the following locally to test:

if (repositories.length > 15) {
log.info(
`repository indicators have been disabled while we investigate reducing the overhead of the computation work as you have ${
repositories.length
} tracked repositories`
)
return
}

Updated that number to 25 (I have 21 local repos)

const updateRepoInfoInterval = 1000 * 60 * 15

Updated to refresh every minute.

@iAmWillShepherd iAmWillShepherd added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Aug 2, 2018
Comment thread app/src/lib/stores/app-store.ts Outdated
const now = new Date()
const timeSinceFetch = now.getTime() - lastFetched.getTime()

const repoName =

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated
* @param gitStore Git information about the repository
* @param repository the local repository tracked by Desktop
*/
private async inferLastPushForRepository(

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated
}

if (repository.gitHubRepository !== null) {
const api = API.fromAccount(account)

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated
}

// we should fetch if the last push happened after the last fetch
const shouldFetch = lastFetched < lastPush

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated
gitStore,
repository
)
if (this.shouldBackgroundFetch(repo, lastPush)) {

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated
await gitStore.updateLastFetched()

if (this.shouldBackgroundFetch(repository, lastPush)) {
await gitStore.loadRemotes()

This comment was marked as spam.

Comment thread app/src/lib/stores/app-store.ts Outdated

log.debug(
`Skipping background fetch since nothing has been pushed to '${repoName}' since the last fetch at ${new Date(
lastFetched

This comment was marked as spam.

account,
r => this.performFetch(r, account, FetchType.BackgroundTask),
r => this.shouldBackgroundFetch(r)
r => this.shouldBackgroundFetch(r, null)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@iAmWillShepherd

Copy link
Copy Markdown
Contributor Author

💯

@shiftkey shiftkey added this to the 1.3.3 milestone Aug 8, 2018
@shiftkey

shiftkey commented Aug 9, 2018

Copy link
Copy Markdown
Member

Going to merge this in early because I want to build upon these changes 🏎

@shiftkey
shiftkey merged commit b3494e1 into master Aug 9, 2018
@shiftkey
shiftkey deleted the check-before-fetch branch August 9, 2018 12:01

@Shohag1985 Shohag1985 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants