Skip to content

Commit

Permalink
Make the Refresh File Tree command clear caches as well to ensure a f…
Browse files Browse the repository at this point in the history
…ull refresh.

As suggested in adobe#7929.
  • Loading branch information
dangoor committed Oct 29, 2014
1 parent e23f7b6 commit 8331ec7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/filesystem/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,18 @@ define(function (require, exports, module) {
}
}
};


/**
* Clears all cached content. Because of the performance implications of this, this should only be used if
* there is a suspicion that the file system has not been updated through the normal file watchers
* mechanism.
*/
FileSystem.prototype.clearAllCaches = function () {
this._index.visitAll(function (entry) {
entry._clearCachedData(true);
});
};

/**
* Start watching a filesystem root entry.
*
Expand Down Expand Up @@ -965,6 +976,7 @@ define(function (require, exports, module) {
exports.showSaveDialog = _wrap(FileSystem.prototype.showSaveDialog);
exports.watch = _wrap(FileSystem.prototype.watch);
exports.unwatch = _wrap(FileSystem.prototype.unwatch);
exports.clearAllCaches = _wrap(FileSystem.prototype.clearAllCaches);

// Static public utility methods
exports.isAbsolutePath = FileSystem.isAbsolutePath;
Expand Down
15 changes: 13 additions & 2 deletions src/project/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,19 @@ define(function (require, exports, module) {
});
}
};

/**
* @private
*
* Clear all caches associated with the project.
*/
ProjectModel.prototype._clearAllCaches = function () {
this._resetCache();
FileSystem.clearAllCaches();
};

/**
* Refreshes the contents of the tree.
* Clears caches and refreshes the contents of the tree.
*
* @return {$.Promise} resolved when the tree has been refreshed
*/
Expand All @@ -1088,7 +1098,8 @@ define(function (require, exports, module) {
selections = this._selections,
viewModel = this._viewModel,
deferred = new $.Deferred();


this._clearAllCaches();
this.setProjectRoot(projectRoot).then(function () {
self.reopenNodes(openNodes).then(function () {
if (selections.selected) {
Expand Down
2 changes: 2 additions & 0 deletions test/spec/ProjectModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ define(function (require, exports, module) {

it("should refresh the whole tree", function () {
var oldTree;
spyOn(model, "_clearAllCaches");
waitsForDone(model.reopenNodes(data.nodesByDepth));
runs(function () {
model.setSelected("/foo/subdir1/subsubdir/interior.txt");
Expand All @@ -1102,6 +1103,7 @@ define(function (require, exports, module) {
expect(vm._treeData.getIn(["subdir1", "children", "subsubdir", "children", "newInterior.txt"])).toBeDefined();
expect(vm._treeData.getIn(["subdir1", "children", "subsubdir", "children", "interior.txt"])).toBeUndefined();
expect(vm._treeData.getIn(["subdir3", "children", "higher.txt", "context"])).toBe(true);
expect(model._clearAllCaches).toHaveBeenCalled();
});
});
});
Expand Down

0 comments on commit 8331ec7

Please sign in to comment.