From cf3a61a8e3ad76753c802195381e05a5f8d6a9b0 Mon Sep 17 00:00:00 2001 From: Giuseppe Piscopo Date: Mon, 8 Apr 2024 12:01:48 +0200 Subject: [PATCH 1/3] chore(middleware): add sandbox to show issue with growing cache --- sandbox/middleware-instances.html.example | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 sandbox/middleware-instances.html.example diff --git a/sandbox/middleware-instances.html.example b/sandbox/middleware-instances.html.example new file mode 100644 index 0000000000..b33e6b6169 --- /dev/null +++ b/sandbox/middleware-instances.html.example @@ -0,0 +1,71 @@ + + + + + Video.js Sandbox + + + + + +
+

You can use /sandbox/ for writing and testing your own code. Nothing in /sandbox/ will get checked into the repo, except files that end in .example (so don't edit or add those files). To get started run `npm start` and open the index.html

+
npm start
+
open http://localhost:9999/sandbox/index.html
+
+ +
+

+ In developer console, Sources tab, look for clearCacheForPlayer function. + Place a logpoint at function closing. Logpoint content should be: +

+
'middlewareInstances nr', Object.keys(middlewareInstances).length
+

+ When one or more players are removed, the number of instances should *NOT* grow. +

+
+ +
+ + +
+ +
+ + + + + From d189f9bf0f18fed068e028c343965e8e1b48deaa Mon Sep 17 00:00:00 2001 From: Giuseppe Piscopo Date: Mon, 8 Apr 2024 12:02:49 +0200 Subject: [PATCH 2/3] fix(middleware): when player is removed and no middleware was set, prevent cache from growing with null value --- src/js/tech/middleware.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/tech/middleware.js b/src/js/tech/middleware.js index 5eebac619a..353e3aafb1 100644 --- a/src/js/tech/middleware.js +++ b/src/js/tech/middleware.js @@ -244,7 +244,9 @@ function executeRight(mws, method, value, terminated) { * A {@link Player} instance. */ export function clearCacheForPlayer(player) { - middlewareInstances[player.id()] = null; + if (middlewareInstances.hasOwnProperty(player.id())) { + middlewareInstances[player.id()] = null; + } } /** From 9c116f106211903e9ab794c0938adcad50e732aa Mon Sep 17 00:00:00 2001 From: Giuseppe Piscopo Date: Thu, 20 Jun 2024 10:29:11 +0200 Subject: [PATCH 3/3] refactor(middleware): when player is removed and no middleware was set, delete cache key instead of setting to null --- src/js/tech/middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/tech/middleware.js b/src/js/tech/middleware.js index 62e11a1c04..78182c4a28 100644 --- a/src/js/tech/middleware.js +++ b/src/js/tech/middleware.js @@ -248,7 +248,7 @@ function executeRight(mws, method, value, terminated) { */ export function clearCacheForPlayer(player) { if (middlewareInstances.hasOwnProperty(player.id())) { - middlewareInstances[player.id()] = null; + delete middlewareInstances[player.id()]; } }