Added redis oplog with collection caching
This commit is contained in:
3
app/imports/server/config/redisCaching.js
Normal file
3
app/imports/server/config/redisCaching.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||
|
||||
LibraryNodes.startCaching();
|
||||
@@ -5,27 +5,33 @@ import getCreatureLibraryIds from '/imports/api/library/getCreatureLibraryIds.js
|
||||
import getUserLibraryIds from '/imports/api/library/getUserLibraryIds.js';
|
||||
import { assertViewPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||
|
||||
Meteor.publish('selectedLibraryNodes', function(selectedNodeIds){
|
||||
function escapeRegex(string) {
|
||||
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '');
|
||||
}
|
||||
|
||||
Meteor.publish('selectedLibraryNodes', function (selectedNodeIds) {
|
||||
check(selectedNodeIds, Array);
|
||||
// Limit to 20 selected nodes
|
||||
if (selectedNodeIds.length > 20){
|
||||
if (selectedNodeIds.length > 20) {
|
||||
selectedNodeIds = selectedNodeIds.slice(0, 20);
|
||||
}
|
||||
let libraryViewPermissions = {};
|
||||
// Check view permissions of all libraries
|
||||
for (let id of selectedNodeIds){
|
||||
for (let id of selectedNodeIds) {
|
||||
let node = LibraryNodes.findOne(id);
|
||||
if (!node) continue;
|
||||
let libraryId = node.ancestors[0].id;
|
||||
if (libraryViewPermissions[id]){
|
||||
if (libraryViewPermissions[id]) {
|
||||
continue;
|
||||
} else {
|
||||
let library = Libraries.findOne(libraryId, {fields: {
|
||||
owner: 1,
|
||||
readers: 1,
|
||||
writers: 1,
|
||||
public: 1,
|
||||
}});
|
||||
let library = Libraries.findOne(libraryId, {
|
||||
fields: {
|
||||
owner: 1,
|
||||
readers: 1,
|
||||
writers: 1,
|
||||
public: 1,
|
||||
}
|
||||
});
|
||||
assertViewPermission(library, this.userId);
|
||||
libraryViewPermissions[id] = true;
|
||||
}
|
||||
@@ -33,15 +39,15 @@ Meteor.publish('selectedLibraryNodes', function(selectedNodeIds){
|
||||
// Return all nodes and their children
|
||||
return [LibraryNodes.find({
|
||||
$or: [
|
||||
{_id: {$in: selectedNodeIds}},
|
||||
{'ancestors.id': {$in: selectedNodeIds}},
|
||||
{ _id: { $in: selectedNodeIds } },
|
||||
{ 'ancestors.id': { $in: selectedNodeIds } },
|
||||
],
|
||||
})];
|
||||
});
|
||||
|
||||
Meteor.publish('searchLibraryNodes', function(creatureId){
|
||||
Meteor.publish('searchLibraryNodes', function (creatureId) {
|
||||
let self = this;
|
||||
this.autorun(function (){
|
||||
this.autorun(function () {
|
||||
let type = self.data('type');
|
||||
if (!type) return [];
|
||||
|
||||
@@ -60,20 +66,20 @@ Meteor.publish('searchLibraryNodes', function(creatureId){
|
||||
|
||||
// Build a filter for nodes in those libraries that match the type
|
||||
let filter = {
|
||||
'ancestors.id': {$in: libraryIds},
|
||||
removed: {$ne: true},
|
||||
tags: {$ne: []}, // Only tagged library nodes are considered
|
||||
'ancestors.id': { $in: libraryIds },
|
||||
removed: { $ne: true },
|
||||
tags: { $ne: [] }, // Only tagged library nodes are considered
|
||||
};
|
||||
if (type){
|
||||
if (type) {
|
||||
filter.$or = [{
|
||||
type,
|
||||
},{
|
||||
type: 'slotFiller',
|
||||
slotFillerType: type,
|
||||
type,
|
||||
}, {
|
||||
type: 'slotFiller',
|
||||
slotFillerType: type,
|
||||
}];
|
||||
}
|
||||
|
||||
this.autorun(function(){
|
||||
this.autorun(function () {
|
||||
// Get the limit of the documents the user can fetch
|
||||
var limit = self.data('limit') || 32;
|
||||
check(limit, Number);
|
||||
@@ -83,28 +89,34 @@ Meteor.publish('searchLibraryNodes', function(creatureId){
|
||||
check(searchTerm, String);
|
||||
|
||||
let options = undefined;
|
||||
if (searchTerm){
|
||||
filter.$text = {$search: searchTerm};
|
||||
if (searchTerm) {
|
||||
filter.name = { $regex: escapeRegex(searchTerm), '$options': 'i' };
|
||||
// filter.$text = {$search: searchTerm};
|
||||
options = {
|
||||
/*
|
||||
// relevant documents have a higher score.
|
||||
fields: {
|
||||
score: { $meta: 'textScore' }
|
||||
},
|
||||
*/
|
||||
sort: {
|
||||
// `score` property specified in the projection fields above.
|
||||
score: { $meta: 'textScore' },
|
||||
// score: { $meta: 'textScore' },
|
||||
'ancestors.0.id': 1,
|
||||
name: 1,
|
||||
order: 1,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete filter.$text
|
||||
options = {sort: {
|
||||
'ancestors.0.id': 1,
|
||||
name: 1,
|
||||
order: 1,
|
||||
}};
|
||||
//delete filter.$text
|
||||
delete filter.name;
|
||||
options = {
|
||||
sort: {
|
||||
'ancestors.0.id': 1,
|
||||
name: 1,
|
||||
order: 1,
|
||||
}
|
||||
};
|
||||
}
|
||||
options.limit = limit;
|
||||
|
||||
@@ -118,17 +130,17 @@ Meteor.publish('searchLibraryNodes', function(creatureId){
|
||||
Mongo.Collection._publishCursor(libraries, self, 'libraries');
|
||||
|
||||
let observeHandle = cursor.observeChanges({
|
||||
added: function (id, fields) {
|
||||
fields._searchResult = true;
|
||||
self.added('libraryNodes', id, fields);
|
||||
},
|
||||
changed: function (id, fields) {
|
||||
self.changed('libraryNodes', id, fields);
|
||||
},
|
||||
removed: function (id) {
|
||||
self.removed('libraryNodes', id);
|
||||
}
|
||||
added: function (id, fields) {
|
||||
fields._searchResult = true;
|
||||
self.added('libraryNodes', id, fields);
|
||||
},
|
||||
changed: function (id, fields) {
|
||||
self.changed('libraryNodes', id, fields);
|
||||
},
|
||||
removed: function (id) {
|
||||
self.removed('libraryNodes', id);
|
||||
}
|
||||
},
|
||||
// Publications don't mutate the documents
|
||||
{ nonMutatingCallbacks: true }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user