Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions lib/controllers/root-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import GitTabController from './git-tab-controller';
import StatusBarTileController from './status-bar-tile-controller';
import RepositoryConflictController from './repository-conflict-controller';
import GithubLoginModel from '../models/github-login-model';
import GitCacheView from '../views/git-cache-view';
import Conflict from '../models/conflicts/conflict';
import RefHolder from '../models/ref-holder';
import Switchboard from '../switchboard';
Expand Down Expand Up @@ -115,6 +116,7 @@ export default class RootController extends React.Component {
{devMode && <Command command="github:install-react-dev-tools" callback={this.installReactDevTools} />}
<Command command="github:logout" callback={this.clearGithubToken} />
<Command command="github:show-waterfall-diagnostics" callback={this.showWaterfallDiagnostics} />
<Command command="github:show-cache-diagnostics" callback={this.showCacheDiagnostics} />
<Command command="github:open-issue-or-pull-request" callback={this.showOpenIssueishDialog} />
<Command command="github:toggle-git-tab" callback={this.gitTabTracker.toggle} />
<Command command="github:toggle-git-tab-focus" callback={this.gitTabTracker.toggleFocus} />
Expand Down Expand Up @@ -343,6 +345,9 @@ export default class RootController extends React.Component {
<PaneItem workspace={this.props.workspace} uriPattern={GitTimingsView.uriPattern}>
{({itemHolder}) => <GitTimingsView ref={itemHolder.setter} />}
</PaneItem>
<PaneItem workspace={this.props.workspace} uriPattern={GitCacheView.uriPattern}>
{({itemHolder}) => <GitCacheView ref={itemHolder.setter} repository={this.props.repository} />}
</PaneItem>
</Fragment>
);
}
Expand Down Expand Up @@ -404,6 +409,11 @@ export default class RootController extends React.Component {
this.props.workspace.open(GitTimingsView.buildURI());
}

@autobind
showCacheDiagnostics() {
this.props.workspace.open(GitCacheView.buildURI());
}

@autobind
async acceptClone(remoteUrl, projectPath) {
this.setState({cloneDialogInProgress: true});
Expand Down
6 changes: 6 additions & 0 deletions lib/models/branch-set.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import util from 'util';

import {nullBranch} from './branch';

function pushAtKey(map, key, value) {
Expand Down Expand Up @@ -60,4 +62,8 @@ export default class BranchSet {
getPushSources(remoteName, remoteRefName) {
return this.byPushRef.get(`${remoteName}\0${remoteRefName}`) || [];
}

[util.inspect.custom](depth, options) {
return `BranchSet {${util.inspect(this.all)}}`;
}
}
6 changes: 6 additions & 0 deletions lib/models/branch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import util from 'util';

const DETACHED = Symbol('detached');
const REMOTE_TRACKING = Symbol('remote-tracking');

Expand Down Expand Up @@ -132,4 +134,8 @@ export const nullBranch = {
isPresent() {
return false;
},

[util.inspect.custom](depth, options) {
return '{nullBranch}';
},
};
47 changes: 45 additions & 2 deletions lib/models/repository-states/present.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import {Emitter} from 'event-kit';
import fs from 'fs-extra';

import State from './state';
Expand Down Expand Up @@ -87,6 +88,11 @@ export default class Present extends State {
return true;
}

destroy() {
this.cache.destroy();
super.destroy();
}

showStatusBarTiles() {
return true;
}
Expand Down Expand Up @@ -695,6 +701,11 @@ export default class Present extends State {
getLastHistorySnapshots(partialDiscardFilePath = null) {
return this.discardHistory.getLastSnapshots(partialDiscardFilePath);
}

// Cache
getCache() {
return this.cache;
}
}

State.register(Present);
Expand Down Expand Up @@ -818,18 +829,25 @@ class Cache {
constructor() {
this.storage = new Map();
this.byGroup = new Map();

this.emitter = new Emitter();
}

getOrSet(key, operation) {
const primary = key.getPrimary();
const existing = this.storage.get(primary);
if (existing !== undefined) {
return existing;
existing.hits++;
return existing.promise;
}

const created = operation();

this.storage.set(primary, created);
this.storage.set(primary, {
createdAt: performance.now(),
hits: 0,
promise: created,
});

const groups = key.getGroups();
for (let i = 0; i < groups.length; i++) {
Expand All @@ -842,13 +860,19 @@ class Cache {
groupSet.add(key);
}

this.didUpdate();

return created;
}

invalidate(keys) {
for (let i = 0; i < keys.length; i++) {
keys[i].removeFromCache(this);
}

if (keys.length > 0) {
this.didUpdate();
}
}

keysInGroup(group) {
Expand All @@ -857,16 +881,35 @@ class Cache {

removePrimary(primary) {
this.storage.delete(primary);
this.didUpdate();
}

removeFromGroup(group, key) {
const groupSet = this.byGroup.get(group);
groupSet && groupSet.delete(key);
this.didUpdate();
}

[Symbol.iterator]() {
return this.storage[Symbol.iterator]();
}

clear() {
this.storage.clear();
this.byGroup.clear();
this.didUpdate();
}

didUpdate() {
this.emitter.emit('did-update');
}

onDidUpdate(callback) {
return this.emitter.on('did-update', callback);
}

destroy() {
this.emitter.dispose();
}
}

Expand Down
7 changes: 7 additions & 0 deletions lib/models/repository-states/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ export default class State {
return '';
}

// Cache

@shouldDelegate
getCache() {
return null;
}

// Internal //////////////////////////////////////////////////////////////////////////////////////////////////////////
// Non-delegated methods that provide subclasses with convenient access to Repository properties.

Expand Down
1 change: 1 addition & 0 deletions lib/models/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ const delegates = [

'setCommitMessage',
'getCommitMessage',
'getCache',
];

for (let i = 0; i < delegates.length; i++) {
Expand Down
Loading