From aac5a4bc55438790d7ab5cbd2960875e04e89f93 Mon Sep 17 00:00:00 2001 From: gwilym Date: Wed, 27 Mar 2024 11:45:42 +1100 Subject: [PATCH] add cache dependency to join table --- .../src/lib/JoinTableControllerSingleton.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js b/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js index 0f7c7837..51c5626e 100644 --- a/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js +++ b/packages/stein-orm-rest/src/lib/JoinTableControllerSingleton.js @@ -38,7 +38,15 @@ class JoinTableControllerSingleton { const joinTableOptions = _.clone(options) joinTableOptions.route = path.join(routeRoot, joinTableEndpoint) if (joinTableOptions.route[0] !== '/') { joinTableOptions.route = `/${joinTableOptions.route}` } - if (this.joinTables[joinTableOptions.route]) return // already exists + + // join table has already been created, make sure this controller is added to the cache dependencies and bail + const existingJoinTable = this.joinTables[joinTableOptions.route] + if (existingJoinTable) { + if (existingJoinTable.cache && existingJoinTable.cache.createHash) { + existingJoinTable.cache.cascade = _.uniq([...(existingJoinTable.cache.cascade || []), existingJoinTable.cache.createHash(options)]) + } + return + } for (const _key of ['whitelist', 'templates', 'defaultTemplate']) { delete joinTableOptions[_key]