Creatures are now cached in memory for computation
Also removed dependency group calculation because the optimisation isn't as useful to reduce DB calls if the creature is in memory anyway
This commit is contained in:
@@ -5,6 +5,7 @@ import CreatureLogs from '/imports/api/creature/log/CreatureLogs.js';
|
||||
import { assertViewPermission } from '/imports/api/creature/creatures/creaturePermissions.js';
|
||||
import computeCreature from '/imports/api/engine/computeCreature.js';
|
||||
import VERSION from '/imports/constants/VERSION.js';
|
||||
import { loadCreature } from '/imports/api/engine/loadCreatures.js';
|
||||
|
||||
let schema = new SimpleSchema({
|
||||
creatureId: {
|
||||
@@ -13,7 +14,8 @@ let schema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish('singleCharacter', function(creatureId){
|
||||
Meteor.publish('singleCharacter', function (creatureId) {
|
||||
const self = this;
|
||||
try {
|
||||
schema.validate({ creatureId });
|
||||
} catch (e){
|
||||
@@ -21,21 +23,24 @@ Meteor.publish('singleCharacter', function(creatureId){
|
||||
}
|
||||
this.autorun(function (computation){
|
||||
let userId = this.userId;
|
||||
let creatureCursor
|
||||
creatureCursor = Creatures.find({
|
||||
let permissionCreature = Creatures.findOne({
|
||||
_id: creatureId,
|
||||
}, {
|
||||
fields: { owner: 1, readers: 1, writers: 1, public: 1, computeVersion: 1 }
|
||||
});
|
||||
let creature = creatureCursor.fetch()[0];
|
||||
try { assertViewPermission(creature, userId) }
|
||||
catch(e){ return [] }
|
||||
if (creature.computeVersion !== VERSION && computation.firstRun){
|
||||
try { assertViewPermission(permissionCreature, userId) }
|
||||
catch (e) { return [] }
|
||||
loadCreature(creatureId, self);
|
||||
if (permissionCreature.computeVersion !== VERSION && computation.firstRun){
|
||||
try {
|
||||
computeCreature(creatureId)
|
||||
}
|
||||
catch(e){ console.error(e) }
|
||||
}
|
||||
return [
|
||||
creatureCursor,
|
||||
Creatures.find({
|
||||
_id: creatureId,
|
||||
}),
|
||||
CreatureProperties.find({
|
||||
'ancestors.id': creatureId,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user