Browse Source

Fixes #635 - removes periodic refresh of repo node

Refreshing a node triggers all children to be re-rendered
Replaces intra-day relative date format with additional time
main
Eric Amodio 6 years ago
parent
commit
0a4c24cd81
2 changed files with 36 additions and 23 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +34
    -23
      src/views/nodes/repositoryNode.ts

+ 2
- 0
CHANGELOG.md View File

@ -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
@ -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

+ 34
- 23
src/views/nodes/repositoryNode.ts View File

@ -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';
@ -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;
@ -98,7 +99,8 @@ export class RepositoryNode extends SubscribeableViewNode {
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;
@ -216,9 +218,9 @@ export class RepositoryNode extends SubscribeableViewNode {
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), {
@ -293,29 +295,38 @@ export class RepositoryNode extends SubscribeableViewNode {
}
}
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);
// }
}

Loading…
Cancel
Save