Libraries only fetch their data whene expanded

This commit is contained in:
Stefan Zermatten
2021-02-27 10:49:10 +02:00
parent 2a983b0a94
commit dc53e38efe
4 changed files with 27 additions and 19 deletions

View File

@@ -32,26 +32,31 @@ Meteor.publish('libraries', function(){
}); });
let libraryIdSchema = new SimpleSchema({ let libraryIdSchema = new SimpleSchema({
libraryId: { libraryIds: {
type: Array,
},
'libraryIds.$':{
type: String, type: String,
regEx: SimpleSchema.RegEx.Id, regEx: SimpleSchema.RegEx.Id,
}, },
}); });
Meteor.publish('library', function(libraryId){ Meteor.publish('libraryNodes', function(libraryIds){
libraryIdSchema.validate({libraryId}); libraryIdSchema.validate({libraryIds});
if (!libraryIds.length) return [];
this.autorun(function (){ this.autorun(function (){
let userId = this.userId; let userId = this.userId;
let libraryCursor = Libraries.find({ for (let i in libraryIds){
_id: libraryId, let libraryId = libraryIds[i];
}); let library = Libraries.findOne(libraryId);
let library = libraryCursor.fetch()[0]; try { assertViewPermission(library, userId) }
try { assertViewPermission(library, userId) } catch(e){
catch(e){ return [] } return this.error(e);
}
}
return [ return [
libraryCursor,
LibraryNodes.find({ LibraryNodes.find({
'ancestors.id': libraryId, 'ancestors.id': {$in: libraryIds},
}, { }, {
sort: {order: 1}, sort: {order: 1},
}), }),

View File

@@ -112,9 +112,6 @@ export default {
getPropertyName, getPropertyName,
}, },
meteor: { meteor: {
$subscribe: {
'libraries': [],
},
libraries(){ libraries(){
return Libraries.find({}, { return Libraries.find({}, {
sort: {name: 1} sort: {name: 1}

View File

@@ -94,6 +94,17 @@ export default {
meteor: { meteor: {
$subscribe: { $subscribe: {
'libraries': [], '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(){ libraries(){
return Libraries.find({}, { return Libraries.find({}, {

View File

@@ -27,11 +27,6 @@
selectedNodeId: String, selectedNodeId: String,
}, },
meteor: { meteor: {
$subscribe: {
'library'(){
return [this.libraryId]
},
},
library(){ library(){
return Libraries.findOne(this.libraryId); return Libraries.findOne(this.libraryId);
}, },