Replace reywood:publish-composite by cottz:publish-relations

Since bug #431 is due to publish-composite I tried to fix this package
and propose a pull request but the code was difficult to refactor. I
decided to use @cottz package instead which handled DDP messages in
the correct order.

Fixes #431
reviewable/pr435/r1
Maxime Quandalle 10 years ago
parent 0954cff5b4
commit 677e9937e0
  1. 2
      .meteor/packages
  2. 2
      .meteor/versions
  3. 139
      server/publications/boards.js

@ -18,13 +18,13 @@ es5-shim
aldeed:collection2 aldeed:collection2
cfs:gridfs cfs:gridfs
cfs:standard-packages cfs:standard-packages
cottz:publish-relations
dburles:collection-helpers dburles:collection-helpers
idmontie:migrations idmontie:migrations
matb33:collection-hooks matb33:collection-hooks
matteodem:easy-search matteodem:easy-search
mongo mongo
mquandalle:collection-mutations mquandalle:collection-mutations
reywood:publish-composite
# Account system # Account system
accounts-password accounts-password

@ -39,6 +39,7 @@ check@1.1.0
chuangbo:cookie@1.1.0 chuangbo:cookie@1.1.0
coffeescript@1.0.11 coffeescript@1.0.11
cosmos:browserify@0.9.2 cosmos:browserify@0.9.2
cottz:publish-relations@2.0.0
dburles:collection-helpers@1.0.4 dburles:collection-helpers@1.0.4
ddp@1.2.2 ddp@1.2.2
ddp-client@1.2.1 ddp-client@1.2.1
@ -119,7 +120,6 @@ reactive-dict@1.1.3
reactive-var@1.0.6 reactive-var@1.0.6
reload@1.1.4 reload@1.1.4
retry@1.0.4 retry@1.0.4
reywood:publish-composite@1.4.2
routepolicy@1.0.6 routepolicy@1.0.6
seriousm:emoji-continued@1.4.0 seriousm:emoji-continued@1.4.0
service-configuration@1.0.5 service-configuration@1.0.5

@ -55,97 +55,58 @@ Meteor.publish('archivedBoards', function() {
}); });
}); });
Meteor.publishComposite('board', function(boardId) { Meteor.publishRelations('board', function(boardId) {
check(boardId, String); check(boardId, String);
return {
find() {
return Boards.find({
_id: boardId,
archived: false,
// If the board is not public the user has to be a member of it to see
// it.
$or: [
{ permission: 'public' },
{ members: { $elemMatch: { userId: this.userId, isActive: true }}},
],
}, { limit: 1 });
},
children: [
// Lists
{
find(board) {
return Lists.find({
boardId: board._id,
});
},
},
// Cards and cards comments this.cursor(Boards.find({
// XXX Originally we were publishing the card documents as a child of the _id: boardId,
// list publication defined above using the following selector `{ listId: archived: false,
// list._id }`. But it was causing a race condition in publish-composite, // If the board is not public the user has to be a member of it to see
// that I documented here: // it.
// $or: [
// https://github.com/englue/meteor-publish-composite/issues/29 { permission: 'public' },
// { members: { $elemMatch: { userId: this.userId, isActive: true }}},
// I then tried to replace publish-composite by cottz:publish, but it had ],
// a similar problem: }, { limit: 1 }), function(boardId, board) {
// this.cursor(Lists.find({ boardId }));
// https://github.com/Goluis/cottz-publish/issues/4
// https://github.com/wekan/wekan/pull/78
//
// The current state of relational publishing in meteor is a bit sad,
// there are a lot of various packages, with various APIs, some of them
// are unmaintained. Fortunately this is something that will be fixed by
// meteor-core at some point:
//
// https://trello.com/c/BGvIwkEa/48-easy-joins-in-subscriptions
//
// And in the meantime our code below works pretty well -- it's not even a
// hack!
{
find(board) {
return Cards.find({
boardId: board._id,
});
},
children: [ // Cards and cards comments
// comments // XXX Originally we were publishing the card documents as a child of the
{ // list publication defined above using the following selector `{ listId:
find(card) { // list._id }`. But it was causing a race condition in publish-composite,
return CardComments.find({ // that I documented here:
cardId: card._id, //
}); // https://github.com/englue/meteor-publish-composite/issues/29
}, //
}, // cottz:publish had a similar problem:
// Attachments //
{ // https://github.com/Goluis/cottz-publish/issues/4
find(card) { //
return Attachments.find({ // The current state of relational publishing in meteor is a bit sad,
cardId: card._id, // there are a lot of various packages, with various APIs, some of them
}); // are unmaintained. Fortunately this is something that will be fixed by
}, // meteor-core at some point:
}, //
], // https://trello.com/c/BGvIwkEa/48-easy-joins-in-subscriptions
}, //
// And in the meantime our code below works pretty well -- it's not even a
// hack!
this.cursor(Cards.find({ boardId }), function(cardId) {
this.cursor(CardComments.find({ cardId }));
this.cursor(Attachments.find({ cardId }));
});
// Board members. This publication also includes former board members that // Board members. This publication also includes former board members that
// aren't members anymore but may have some activities attached to them in // aren't members anymore but may have some activities attached to them in
// the history. // the history.
{ //
find(board) { this.cursor(Users.find({
return Users.find({ _id: { $in: _.pluck(board.members, 'userId') },
_id: { $in: _.pluck(board.members, 'userId') }, }), function(userId) {
}); // Presence indicators
}, this.cursor(presences.find({ userId }));
// Presence indicators });
children: [{ });
find(user) {
return presences.find({userId: user._id}); return this.ready();
},
}],
},
],
};
}); });

Loading…
Cancel
Save