Began migration of queries to nested sets
This commit is contained in:
@@ -9,7 +9,8 @@ import {
|
||||
} from '/imports/api/sharing/sharingPermissions';
|
||||
import {
|
||||
setLineageOfDocs,
|
||||
renewDocIds
|
||||
renewDocIds,
|
||||
getFilter
|
||||
} from '/imports/api/parenting/parentingFunctions';
|
||||
import { rebuildNestedSets } from '/imports/api/parenting/parentingFunctions';
|
||||
import { fetchDocByRef } from '/imports/api/parenting/parentingFunctions';
|
||||
@@ -46,12 +47,14 @@ const copyLibraryNodeTo = new ValidatedMethod({
|
||||
);
|
||||
}
|
||||
const libraryNode = LibraryNodes.findOne(_id);
|
||||
if (!libraryNode) throw new Meteor.Error('not-found', 'Library node was not found');
|
||||
|
||||
const parentDoc = fetchDocByRef(parent);
|
||||
assertDocCopyPermission(libraryNode, this.userId);
|
||||
assertDocEditPermission(parentDoc, this.userId);
|
||||
|
||||
let decendants = LibraryNodes.find({
|
||||
'ancestors.id': _id,
|
||||
...getFilter.descendants(libraryNode),
|
||||
removed: { $ne: true },
|
||||
}, {
|
||||
limit: DUPLICATE_CHILDREN_LIMIT + 1,
|
||||
@@ -69,26 +72,16 @@ const copyLibraryNodeTo = new ValidatedMethod({
|
||||
|
||||
const nodes = [libraryNode, ...decendants];
|
||||
|
||||
const newAncestry = parentDoc.ancestors || [];
|
||||
newAncestry.push(parent);
|
||||
// re-map all the ancestors
|
||||
setLineageOfDocs({
|
||||
docArray: nodes,
|
||||
newAncestry,
|
||||
oldParent: libraryNode.parent,
|
||||
});
|
||||
|
||||
// Give the docs new IDs without breaking internal references
|
||||
renewDocIds({ docArray: nodes });
|
||||
|
||||
// Order the root node
|
||||
libraryNode.order = (parentDoc.order || 0) + 0.5;
|
||||
libraryNode.left = Number.MAX_SAFE_INTEGER - 1;
|
||||
libraryNode.right = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
LibraryNodes.batchInsert(nodes);
|
||||
|
||||
// Tree structure changed by inserts, reorder the tree
|
||||
// TODO: rebuild tree nested sets
|
||||
|
||||
rebuildNestedSets(LibraryNodes, parentDoc.root.id);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -5,7 +5,8 @@ import LibraryNodes from '/imports/api/library/LibraryNodes';
|
||||
import { assertDocEditPermission } from '/imports/api/sharing/sharingPermissions';
|
||||
import {
|
||||
setLineageOfDocs,
|
||||
renewDocIds
|
||||
renewDocIds,
|
||||
getFilter
|
||||
} from '/imports/api/parenting/parentingFunctions';
|
||||
import { rebuildNestedSets } from '/imports/api/parenting/parentingFunctions';
|
||||
|
||||
@@ -33,6 +34,8 @@ const duplicateLibraryNode = new ValidatedMethod({
|
||||
},
|
||||
run({ _id }) {
|
||||
let libraryNode = LibraryNodes.findOne(_id);
|
||||
if (!libraryNode) throw new Meteor.Error('not-found', 'Library node was not found');
|
||||
|
||||
assertDocEditPermission(libraryNode, this.userId);
|
||||
|
||||
let randomSrc = DDP.randomStream('duplicateLibraryNode');
|
||||
@@ -40,7 +43,7 @@ const duplicateLibraryNode = new ValidatedMethod({
|
||||
libraryNode._id = libraryNodeId;
|
||||
|
||||
let nodes = LibraryNodes.find({
|
||||
'ancestors.id': _id,
|
||||
...getFilter.descendants(libraryNode),
|
||||
removed: { $ne: true },
|
||||
}, {
|
||||
limit: DUPLICATE_CHILDREN_LIMIT + 1,
|
||||
@@ -56,16 +59,6 @@ const duplicateLibraryNode = new ValidatedMethod({
|
||||
}
|
||||
}
|
||||
|
||||
// re-map all the ancestors
|
||||
setLineageOfDocs({
|
||||
docArray: nodes,
|
||||
newAncestry: [
|
||||
...libraryNode.ancestors,
|
||||
{ id: libraryNodeId, collection: 'libraryNodes' }
|
||||
],
|
||||
oldParent: { id: _id, collection: 'libraryNodes' },
|
||||
});
|
||||
|
||||
// Give the docs new IDs without breaking internal references
|
||||
const allNodes = [libraryNode, ...nodes];
|
||||
renewDocIds({ docArray: allNodes });
|
||||
@@ -76,10 +69,7 @@ const duplicateLibraryNode = new ValidatedMethod({
|
||||
LibraryNodes.batchInsert(allNodes);
|
||||
|
||||
// Tree structure changed by inserts, reorder the tree
|
||||
reorderDocs({
|
||||
collection: LibraryNodes,
|
||||
ancestorId: libraryNode.ancestors[0].id,
|
||||
});
|
||||
rebuildNestedSets(LibraryNodes, libraryNode.root.id);
|
||||
|
||||
return libraryNodeId;
|
||||
},
|
||||
|
||||
@@ -11,8 +11,8 @@ export default function getDefaultSlotFiller(slot) {
|
||||
type: slotType,
|
||||
libraryTags: slot.slotTags || [],
|
||||
name: 'Custom ' + slot.name || 'slot filler',
|
||||
parent: { collection: 'creatureProperties', id: slot._id },
|
||||
ancestors: [...slot.ancestors, { collection: 'creatureProperties', id: slot._id }],
|
||||
parentId: slot._id,
|
||||
root: { ...slot.root },
|
||||
};
|
||||
return filler;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ function updateReferenceNodeWork(node, userId) {
|
||||
try {
|
||||
doc = fetchDocByRef(node.ref);
|
||||
if (doc.removed) throw 'Property has been deleted';
|
||||
if (doc.ancestors[0].id !== node.ancestors[0].id) {
|
||||
library = fetchDocByRef(doc.ancestors[0]);
|
||||
if (doc.root.id !== node.root.id) {
|
||||
library = fetchDocByRef(doc.root);
|
||||
assertViewPermission(library, userId)
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user