Skip to content

Commit

Permalink
Fixes #635 - removes periodic refresh of repo node
Browse files Browse the repository at this point in the history
Refreshing a node triggers all children to be re-rendered
Replaces intra-day relative date format with additional time
  • Loading branch information
eamodio committed Jan 24, 2019
1 parent 0a35811 commit 0a4c24c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Changed

- Changes the sorting of remotes in the _Repositories_ view to sort the default remote first
- Changes relative date formatting of the last fetched date of repositories in the _Repositories_ view to instead use an absolute format and will additionally add the time of day if less than a day has passed. This avoids having to periodically refresh the repository (which causes all of its children to re-render) in order to update the relative time

### Fixed

Expand All @@ -17,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Fixes [#626](https://github.com/eamodio/vscode-gitlens/issues/626) - Branch names with only digits always appear first — thanks to [PR #627](https://github.com/eamodio/vscode-gitlens/pull/627) by Marc Lasson ([@mlasson](https://github.com/mlasson))
- Fixes [#631](https://github.com/eamodio/vscode-gitlens/issues/631) - Remotes fail to show in gui
- Fixes [#633](https://github.com/eamodio/vscode-gitlens/issues/633) - Compare File with Previous Revision doesn't work if path contains '#'
- Fixes [#635](https://github.com/eamodio/vscode-gitlens/issues/635) - Show more commit not working properly
- Fixes an issue where the _Open File_, _Open File on Remote_, and _Copy Remote Url to Clipboard_ commands didn't always work on changed files in the _Repositories_ view
- Fixes an issue where the default remote wasn't used first to provide automatic issue linking

Expand Down
57 changes: 34 additions & 23 deletions src/views/nodes/repositoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
RepositoryChangeEvent,
RepositoryFileSystemChangeEvent
} from '../../git/gitService';
import { Dates, debug, Functions, gate, log, Strings } from '../../system';
import { DateStyle } from '../../ui/config';
import { Dates, debug, gate, log, Strings } from '../../system';
import { RepositoriesView } from '../repositoriesView';
import { BranchesNode } from './branchesNode';
import { BranchNode } from './branchNode';
Expand All @@ -24,6 +23,8 @@ import { StatusFilesNode } from './statusFilesNode';
import { TagsNode } from './tagsNode';
import { ResourceType, SubscribeableViewNode, ViewNode } from './viewNode';

const hasTimeRegex = /[hHm]/;

export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
private _children: ViewNode[] | undefined;
private _lastFetched: number = 0;
Expand Down Expand Up @@ -98,7 +99,8 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {

const lastFetchedTooltip = this.formatLastFetched({
prefix: `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched on `,
format: Container.config.defaultDateFormat || 'dddd MMMM Do, YYYY h:mm a'
format: Container.config.defaultDateFormat || 'dddd MMMM Do, YYYY',
includeTime: true
});

let description;
Expand Down Expand Up @@ -216,9 +218,9 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
protected async subscribe() {
const disposables = [this.repo.onDidChange(this.onRepoChanged, this)];

if (Container.config.defaultDateStyle === DateStyle.Relative) {
disposables.push(Functions.interval(() => void this.updateLastFetched(), 60000));
}
// if (Container.config.defaultDateStyle === DateStyle.Relative) {
// disposables.push(Functions.interval(() => void this.updateLastFetched(), 60000));
// }

if (this.includeWorkingTree) {
disposables.push(this.repo.onDidChangeFileSystem(this.onFileSystemChanged, this), {
Expand Down Expand Up @@ -293,29 +295,38 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
}
}

private formatLastFetched(options: { prefix?: string; format?: string } = {}) {
private formatLastFetched(options: { prefix?: string; format?: string; includeTime?: boolean } = {}) {
if (this._lastFetched === 0) return '';

if (options.format === undefined && Container.config.defaultDateStyle === DateStyle.Relative) {
// If less than a day has passed show a relative date
if (Date.now() - this._lastFetched < Dates.MillisecondsPerDay) {
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).fromNow()}`;
}
// if (options.format === undefined && Container.config.defaultDateStyle === DateStyle.Relative) {
// // If less than a day has passed show a relative date
// if (Date.now() - this._lastFetched < Dates.MillisecondsPerDay) {
// return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).fromNow()}`;
// }
// }

let format = options.format || Container.config.defaultDateShortFormat || 'MMM D, YYYY';
if (
(options.includeTime ||
// If less than a day has passed show the time too
(options.includeTime === undefined && Date.now() - this._lastFetched < Dates.MillisecondsPerDay)) &&
// If the time is already included don't do anything
!hasTimeRegex.test(format)
) {
format = `h:mma, ${format}`;
}

return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).format(
options.format || Container.config.defaultDateShortFormat || 'MMM D, YYYY'
)}`;
return `${options.prefix || ''}${Dates.toFormatter(new Date(this._lastFetched)).format(format)}`;
}

@debug()
private async updateLastFetched() {
const prevLastFetched = this._lastFetched;
this._lastFetched = await this.repo.getLastFetched();
// @debug()
// private async updateLastFetched() {
// const prevLastFetched = this._lastFetched;
// this._lastFetched = await this.repo.getLastFetched();

// If the fetched date hasn't changed and it was over a day ago, kick out
if (this._lastFetched === prevLastFetched && Date.now() - this._lastFetched >= Dates.MillisecondsPerDay) return;
// // If the fetched date hasn't changed and it was over a day ago, kick out
// if (this._lastFetched === prevLastFetched && Date.now() - this._lastFetched >= Dates.MillisecondsPerDay) return;

this.view.triggerNodeChange(this);
}
// this.view.triggerNodeChange(this);
// }
}

0 comments on commit 0a4c24c

Please sign in to comment.