我有一个大型可搜索数据集。在呈现页面之前发送整个数据集的速度令人无法接受,因此我们目前只是发送包含搜索的部分,因此
if ( Meteor.isClient ) {
Meteor.subscribe('events', Session.get('searchQuery'));
}
if ( Meteor.isServer ) {
Meteor.publish('events', function(searchQuery) {
return Events.find(searchQuery);
}
}
假设我在 1 月份有 10,000 个事件,在 2 月份有 5,000 个事件。
//forgive the psuedo code
Session.set('searchQuery', { startDate: "2015-01-01", endDate: "2015-02-28"});
//wait a bit...
Event.find().count() // => 15,000, as expected.
//now I want to look at just February events
Session.set('searchQuery', { startDate: "2015-02-01", endDate: "2015-02-28"});
Event.find().count() // => 5,000, I've lost the January events.
// now I want to look at *just* the January events
// (I previously fetched these but subsequently lost them)
Session.set('searchQuery', { startDate: "2015-01-01", endDate: "2015-01-31"});
Event.find().count() // => 10,000, it takes a while to get all 10,000 records again.
我想要的是只需要发布一次这些记录,并且由此产生的客户端集合是所有先前结果的联合。
Session.set('searchQuery', { startDate: "2015-01-01", endDate: "2015-02-28"});
//wait a bit...
Event.find().count() // => 15,000, as expected.
//now I want to look at just February events
Session.set('searchQuery', { startDate: "2015-02-01", endDate: "2015-02-28"});
Event.find().count() // => 15,000, I've retained the January events.
Event.find({ startDate: "2015-02-01", endDate: "2015-02-28"}).count() // => 5,000
// now I want to look at *just* the January events
// (I previously fetched these but subsequently lost them)
Session.set('searchQuery', { startDate: "2015-01-01", endDate: "2015-02-31"});
Event.find().count() // => 15,000, still have all the records
Event.find({ startDate: "2015-01-01", endDate: "2015-01-31"}).count() // => 10,000, instantly without needing the records to be republished
我不认为 pub/sub 像这样开箱即用,但是有什么方法可以近似这种行为吗?