Skip to content

Commit

Permalink
fix(cache): fixed caching mechanism broken due to random shuffling in…
Browse files Browse the repository at this point in the history
… the first place
  • Loading branch information
will-moss committed Oct 25, 2024
1 parent 43b26d9 commit 69c50db
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ const App = () => {
return true;
};
const _shuffleArray = (arr) => {
for (let i = arr.length - 1; i > 0; i--) {
const copy = [...arr];

for (let i = copy.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
[copy[i], copy[j]] = [copy[j], copy[i]];
}

return copy;
};

// Members - Form & Auth management
Expand Down Expand Up @@ -333,15 +337,14 @@ const App = () => {
}

_videoFiles = Object.values(_videoFiles);
_shuffleArray(_videoFiles);

setVideos((freshVideos) => {
if (!hasCache) return _videoFiles;
if (!hasCache) return _shuffleArray(_videoFiles);
else if (hasCache && !_arraysAreEqual(_videoFiles, freshVideos))
return [
return _shuffleArray([
...freshVideos,
..._videoFiles.filter((f) => !freshVideos.some((v) => v.url === f.url)),
];
]);
});
_storeVideos(_videoFiles);

Expand Down

0 comments on commit 69c50db

Please sign in to comment.