Skip to content

Commit

Permalink
Resolve the file name cache fix differently
Browse files Browse the repository at this point in the history
If you don't check the fileSet cache, then it will
attempt to load the same missing json files every
time. That is, if a json file does not exist for a locale,
then attempting to load it will fail, and nothing
stops it from trying again and again to load that same
missing file every time it is requested.
  • Loading branch information
ehoogerbeets committed Oct 10, 2019
1 parent 7bd268b commit 93faa1f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
8 changes: 2 additions & 6 deletions js/lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,7 @@ Utils.loadData = function(params) {

// find the ones we haven't loaded before
files = files.filter(ilib.bind(this, function(file) {
if (typeof root !== 'undefined') {
return dataNotExists(basename, file, root);
} else {
return !ilib.data.cache.fileSet.has(file) && dataNotExists(basename, file, root);
}
return !ilib.data.cache.fileSet.has(Path.join(root, file)) && dataNotExists(basename, file, root);
}));

if (files.length) {
Expand All @@ -489,7 +485,7 @@ Utils.loadData = function(params) {
ilib.data[property] = arr[i];
}
}
ilib.data.cache.fileSet.add(files[i]);
ilib.data.cache.fileSet.add(Path.join(root, files[i]));
}

if (!nonlocale) {
Expand Down
32 changes: 31 additions & 1 deletion js/test/util/testutils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* testutils.js - test the utility routines
*
* Copyright © 2012-2015, 2017-2018 JEDLSoft
* Copyright © 2012-2015, 2017-2019 JEDLSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2031,6 +2031,36 @@ module.exports.testutils = {
}
},

testLoadDataDontMixDifferentBasePaths: function(test) {
ilib.data.foo = ilib.data.foo_de = ilib.data.foo_und_DE = ilib.data.foo_de_DE = undefined;
ilib.setLoaderCallback(mockLoaderNoMulti);
try {
Utils.loadData({
name: "foo.json",
locale: "de-DE",
basePath: "asdf",
callback: function (results) {
test.ok(results);
Utils.loadData({
name: "foo.json",
locale: "de-DE",
basePath: "foobar",
callback: function (results2) {
// if there is a cache miss when it attempts to load a file from disk twice
// then the mock loader will throw an exception, which is expected here
// because the base paths are different and Utils.loadData should try to
// load two files with the same name but different bases.
test.fail();
test.done();
}
});
}
});
} catch (e) {
test.done();
}
},

testLoadDataCacheResultAlreadyMerged: function(test) {
ilib.data.foo = ilib.data.foo_de = ilib.data.foo_und_DE = ilib.data.foo_de_DE = undefined;
ilib.setLoaderCallback(mockLoaderNoMulti);
Expand Down

0 comments on commit 93faa1f

Please sign in to comment.