From 8331ec7f52c7439d94e219a3f0cb1b72c1639c2e Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Wed, 29 Oct 2014 10:41:49 -0400 Subject: [PATCH] Make the Refresh File Tree command clear caches as well to ensure a full refresh. As suggested in #7929. --- src/filesystem/FileSystem.js | 14 +++++++++++++- src/project/ProjectModel.js | 15 +++++++++++++-- test/spec/ProjectModel-test.js | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/filesystem/FileSystem.js b/src/filesystem/FileSystem.js index 8578e1881b9..df019859b89 100644 --- a/src/filesystem/FileSystem.js +++ b/src/filesystem/FileSystem.js @@ -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. * @@ -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; diff --git a/src/project/ProjectModel.js b/src/project/ProjectModel.js index 17bdf883e59..951fd7218b0 100644 --- a/src/project/ProjectModel.js +++ b/src/project/ProjectModel.js @@ -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 */ @@ -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) { diff --git a/test/spec/ProjectModel-test.js b/test/spec/ProjectModel-test.js index 20dcd6da18f..da8d189d74a 100644 --- a/test/spec/ProjectModel-test.js +++ b/test/spec/ProjectModel-test.js @@ -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"); @@ -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(); }); }); });