Hi,
Sorry for the disturbance, I’m trying to understand what should be the best way of fixing my current issue in a personal project in terms of code quality & performance.
I actually use the Account Password to store users in my application, which work fine.
I also use meteor-astronomy
to add some helpers to my user collection in order to ease the development.
Here is my user class (simplified to be digest enough) :
export const User = Class.create(
{
name: "User",
collection: Meteor.users,
fields: {},
helpers: {},
behaviors: {}
};
The thing is, I’m trying to build an administration panel to manage the registered users in the form of a paginated table.
Paginated table and all work fine, but I encounter some issues with two publications.
First, I have an intercom available in every pages of my app which allow the current user to do multiple things (read notifications, messages, etc), which needs the current user information I publish with a first publication. Here is the related publication :
Meteor.publish("user_intercom", function()
{
let user = User.findOne({_id: this.userId});
if (Obj.isFalsy(user) || !user.isActionAllowed())
this.error(Logger.subscriptionError(ErrorCode.PERMISSION_DENIED, {connection: this.connection, userId: this.userId}));
return User.find(this.userId, {fields: UserPublisher.getAllFields(user)});
});
Then, I have the table of users in which I display registered users, which needs said users information I publish with a second publication.
In the first time, I only published the cursor from both collections, but encountered the fact that my client side collection had 50 +1 users per page (the 50 from the table and the one from the intercom, except when the intercom is supposed to be on the table for the page set [50 in this case]).
To solve this, I assumed I had to publish this list in a client side dedicated collection, which I then use to populate my table. Here is the publication for this behavior :
Meteor.publish("user_admin_list", function(limit, skip)
{
let dskip = skip > 0 ? skip : 0;
let dlimit = limit > 0 ? limit: 50;
Mongo.Collection._publishCursor(User.find(
{
_id: {$ne: this.userId}
},
{
limit: dlimit,
skip: dskip,
sort: {createdAt: 1}
}), this, "users-admin-list");
this.ready();
});
This works, but there is some issues with this as well.
First, it doesn’t allow me to use the Schema provided by Astronomy on this client-side collection.
Secondly, I’m a bit worried of introducing many client-side only collection just to solve this particular issue, which I may encounter a lot of time during further development.
A simple solution (even though I find it particularly ugly), would be to count users in the table before displaying and removing current user if there is more than 50 users in the set.
What is the best way of handling such use case ?
Thanks for your reading and response