From 282bd39bfa8d6799761e50fca59f9a1eeb021d85 Mon Sep 17 00:00:00 2001 From: Thomas Hackl Date: Fri, 25 Jul 2025 13:51:05 +0200 Subject: always cache course counts data --- resources/vue/components/tree/StudipTreeList.vue | 23 +++++----- resources/vue/components/tree/StudipTreeTable.vue | 6 +-- .../vue/components/tree/TreeNodeCourseInfo.vue | 26 +++++++---- resources/vue/components/tree/TreeNodeTile.vue | 3 +- resources/vue/mixins/TreeMixin.js | 51 ++++++++++++---------- 5 files changed, 60 insertions(+), 49 deletions(-) diff --git a/resources/vue/components/tree/StudipTreeList.vue b/resources/vue/components/tree/StudipTreeList.vue index dedc403..f0569dd 100644 --- a/resources/vue/components/tree/StudipTreeList.vue +++ b/resources/vue/components/tree/StudipTreeList.vue @@ -221,8 +221,6 @@ export default { } }, data() { - const cachedCourseInfo = this.getCachedNodeCourseInfo(this.node.id, this.semester, this.semClass); - return { currentNode: this.node, isLoading: false, @@ -230,8 +228,8 @@ export default { children: [], courses: [], assistiveLive: '', - subLevelsCourses: cachedCourseInfo.allCourses, - thisLevelCourses: cachedCourseInfo.courses, + subLevelsCourses: null, + thisLevelCourses: null, showingAllCourses: false } }, @@ -251,11 +249,14 @@ export default { }); } - this.getNodeCourseInfo(node, this.semester, this.semClass) - .then(response => { - this.thisLevelCourses = response?.data.courses; - this.subLevelsCourses = response?.data.allCourses; - }); + if (node.attributes.ancestors.length > 1) { + this.getNodeCourseInfo(node, this.semester, this.semClass) + .then(response => { + console.log('Response', response); + this.thisLevelCourses = response?.data.courses; + this.subLevelsCourses = response?.data.allCourses; + }); + } if (this.withCourses) { this.getNodeCourses(node, this.offset, this.semester, this.semClass, '', false) @@ -341,8 +342,8 @@ export default { this.getNodeCourseInfo(this.currentNode, this.semester, this.semClass) .then(response => { - this.thisLevelCourses = response?.data.courses; - this.subLevelsCourses = response?.data.allCourses; + this.thisLevelCourses = response.data.courses; + this.subLevelsCourses = response.data.allcourses; }); if (this.withCourses) { diff --git a/resources/vue/components/tree/StudipTreeTable.vue b/resources/vue/components/tree/StudipTreeTable.vue index c56f944..473753b 100644 --- a/resources/vue/components/tree/StudipTreeTable.vue +++ b/resources/vue/components/tree/StudipTreeTable.vue @@ -241,8 +241,6 @@ export default { } }, data() { - const cachedCourseInfo = this.getCachedNodeCourseInfo(this.node.id, this.semester, this.semClass); - return { currentNode: this.node, isLoading: false, @@ -250,8 +248,8 @@ export default { children: [], courses: [], assistiveLive: '', - subLevelsCourses: cachedCourseInfo.allCourses, - thisLevelCourses: cachedCourseInfo.courses, + subLevelsCourses: null, + thisLevelCourses: null, showingAllCourses: false } }, diff --git a/resources/vue/components/tree/TreeNodeCourseInfo.vue b/resources/vue/components/tree/TreeNodeCourseInfo.vue index 7d9f26a..2e92a09 100644 --- a/resources/vue/components/tree/TreeNodeCourseInfo.vue +++ b/resources/vue/components/tree/TreeNodeCourseInfo.vue @@ -1,5 +1,5 @@ @@ -37,11 +44,9 @@ export default { } }, data() { - const cachedCourseInfo = this.getCachedNodeCourseInfo(this.node.id, this.semester, this.semClass); - return { - allCourseCount: cachedCourseInfo.allCourses, - courseCount: cachedCourseInfo.courses, + allCourseCount: null, + courseCount: null, showingAllCourses: false } }, @@ -57,10 +62,13 @@ export default { this.$emit('showAllCourses', state); }, loadNodeInfo(node) { - this.getNodeCourseInfo(node, this.semester, this.semClass) - .then(info => { - this.courseCount = info?.data.courses ?? 0; - }); + if (node.id) { + this.getNodeCourseInfo(node, this.semester, this.semClass) + .then(info => { + this.courseCount = info?.data.courses; + this.allCourseCount = info?.data.allcourses; + }); + } } }, watch: { diff --git a/resources/vue/components/tree/TreeNodeTile.vue b/resources/vue/components/tree/TreeNodeTile.vue index fb1edd3..3271e03 100644 --- a/resources/vue/components/tree/TreeNodeTile.vue +++ b/resources/vue/components/tree/TreeNodeTile.vue @@ -11,8 +11,7 @@ {{ node.attributes.name }}

- diff --git a/resources/vue/mixins/TreeMixin.js b/resources/vue/mixins/TreeMixin.js index e8ec5c9..385ce84 100644 --- a/resources/vue/mixins/TreeMixin.js +++ b/resources/vue/mixins/TreeMixin.js @@ -61,13 +61,7 @@ export const TreeMixin = { {params: parameters} ); }, - getCachedNodeCourseInfo(node, semesterId, semClass) { - return { - courses: cache.get(['course-count', node.id, semesterId, semClass].join('/')) ?? null, - allCourses: cache.get(['course-count-all', node.id, semesterId, semClass].join('/')) ?? null - }; - }, - getNodeCourseInfo(node, semesterId, semClass = 0) { + getNodeCourseInfo(node, semesterId, semClass = 0, forceLive = false) { let parameters = {}; if (semesterId !== 'all' && semesterId !== '0') { @@ -78,22 +72,33 @@ export const TreeMixin = { parameters['filter[semclass]'] = semClass; } - return requester.addRequest( - STUDIP.URLHelper.getURL('jsonapi.php/v1/tree-node/' + node.id + '/courseinfo'), - parameters - ).then(courseinfo => { - cache.set( - ['course-count', node.id, semesterId, semClass].join('/'), - courseinfo.data.courses ?? 0, - 3 * 60 * 60 - ); - cache.set( - ['course-count-all', node.id, semesterId, semClass].join('/'), - courseinfo.data.allcourses ?? 0, - 3 * 60 * 60 - ); - return courseinfo; - }); + const cachedCourseCount = cache.get(['course-count', node.id, semesterId, semClass].join('/')) ?? -1; + const cachedAllCoursesCount = cache.get(['course-count-all', node.id, semesterId, semClass].join('/')) ?? -1; + if (!forceLive && cachedCourseCount !== -1 && cachedAllCoursesCount !== -1) { + return Promise.resolve({ + data: { + courses: cache.get(['course-count', node.id, semesterId, semClass].join('/')), + allcourses: cache.get(['course-count-all', node.id, semesterId, semClass].join('/')) + } + }); + } else { + return requester.addRequest( + STUDIP.URLHelper.getURL('jsonapi.php/v1/tree-node/' + node.id + '/courseinfo'), + parameters + ).then(courseinfo => { + cache.set( + ['course-count', node.id, semesterId, semClass].join('/'), + courseinfo.data.courses, + 3 * 60 * 60 + ); + cache.set( + ['course-count-all', node.id, semesterId, semClass].join('/'), + courseinfo.data.allcourses, + 3 * 60 * 60 + ); + return courseinfo; + }); + } }, nodeUrl(node_id, semester = null ) { return STUDIP.URLHelper.getURL('', { node_id, semester }) -- cgit v1.0