Began migration of queries to nested sets
This commit is contained in:
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user