From dc53e38efe1c258264b08620455dfeee25aef67d Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sat, 27 Feb 2021 10:49:10 +0200 Subject: [PATCH] Libraries only fetch their data whene expanded --- app/imports/server/publications/library.js | 27 +++++++++++-------- app/imports/ui/library/LibraryAndNode.vue | 3 --- app/imports/ui/library/LibraryBrowser.vue | 11 ++++++++ .../ui/library/LibraryContentsContainer.vue | 5 ---- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/app/imports/server/publications/library.js b/app/imports/server/publications/library.js index b7d3fc11..271df4a8 100644 --- a/app/imports/server/publications/library.js +++ b/app/imports/server/publications/library.js @@ -32,26 +32,31 @@ Meteor.publish('libraries', function(){ }); let libraryIdSchema = new SimpleSchema({ - libraryId: { + libraryIds: { + type: Array, + }, + 'libraryIds.$':{ type: String, regEx: SimpleSchema.RegEx.Id, }, }); -Meteor.publish('library', function(libraryId){ - libraryIdSchema.validate({libraryId}); +Meteor.publish('libraryNodes', function(libraryIds){ + libraryIdSchema.validate({libraryIds}); + if (!libraryIds.length) return []; this.autorun(function (){ let userId = this.userId; - let libraryCursor = Libraries.find({ - _id: libraryId, - }); - let library = libraryCursor.fetch()[0]; - try { assertViewPermission(library, userId) } - catch(e){ return [] } + for (let i in libraryIds){ + let libraryId = libraryIds[i]; + let library = Libraries.findOne(libraryId); + try { assertViewPermission(library, userId) } + catch(e){ + return this.error(e); + } + } return [ - libraryCursor, LibraryNodes.find({ - 'ancestors.id': libraryId, + 'ancestors.id': {$in: libraryIds}, }, { sort: {order: 1}, }), diff --git a/app/imports/ui/library/LibraryAndNode.vue b/app/imports/ui/library/LibraryAndNode.vue index 2fda28b3..e2d11a61 100644 --- a/app/imports/ui/library/LibraryAndNode.vue +++ b/app/imports/ui/library/LibraryAndNode.vue @@ -112,9 +112,6 @@ export default { getPropertyName, }, meteor: { - $subscribe: { - 'libraries': [], - }, libraries(){ return Libraries.find({}, { sort: {name: 1} diff --git a/app/imports/ui/library/LibraryBrowser.vue b/app/imports/ui/library/LibraryBrowser.vue index 60fe5646..e76bfd81 100644 --- a/app/imports/ui/library/LibraryBrowser.vue +++ b/app/imports/ui/library/LibraryBrowser.vue @@ -94,6 +94,17 @@ export default { meteor: { $subscribe: { 'libraries': [], + 'libraryNodes'(){ + if (!this.expandedLibrary) return [[]]; + let libraryIds = []; + this.expandedLibrary.forEach((expanded, index) => { + if (expanded){ + let library = this.libraries[index]; + if (library) libraryIds.push(library._id) + } + }); + return [libraryIds]; + } }, libraries(){ return Libraries.find({}, { diff --git a/app/imports/ui/library/LibraryContentsContainer.vue b/app/imports/ui/library/LibraryContentsContainer.vue index 300e6f8d..114cae5b 100644 --- a/app/imports/ui/library/LibraryContentsContainer.vue +++ b/app/imports/ui/library/LibraryContentsContainer.vue @@ -27,11 +27,6 @@ selectedNodeId: String, }, meteor: { - $subscribe: { - 'library'(){ - return [this.libraryId] - }, - }, library(){ return Libraries.findOne(this.libraryId); },