I’ve a collection called tags
with 4000+ unique documents. These tags are being used to classify items.
This is the current workflow
- User selects an item.
- User clicks on a button called assign tags
- It will open up a modal - here,
onCreated
I’m fetchingtags
using reactive method. which are being loaded intoselect2
. (This 3rd step takes few seconds )
Very roughly, this is what my modal looks like.
// item_tag_modal.js
import { Tags } from '../../../api/tags/tags.js';
Template.item_tag_modal.onCreated(function () {
let instance = this;
instance.tags = new ReactiveVar();
instance.processing = new ReactiveVar(false);
this.autorun(function(){
const result = ReactiveMethod.call("tags.available");
console.log(result.count()); // 4122
tags = result.map(function(t){
return { id:t._id , text:t.title };
});
instance.tags.set(tags);
});
});
Template.item_tag_modal.onRendered(function () {
let instance = this;
Meteor.setTimeout(function() {
let tags = instance.tags.get();
$(".tag-list").select2({
data: tags,
placeholder: 'Tags',
multiple: true,
});
}, 900);
});
Each time fetching of 4000+ documents seems immoral to me. are there any better ways of doing it?
P.S. working with a legacy code here.